Register new objects using custom fields architecture

My idea is:

At the moment there are two objects registered with custom fields: Contact, Company. I would like to add the ability to Mautic core so that its possible to register more objects (for example Product) leavering the existing Mautic custom fields architecture (I know custom fields do not leverage the best design, but it is the one we have).

In order to register new custom object and enable adding new custom fields to that object you have to do the following:

  • We have to create new entity that implements CustomFieldEntityInterface, CustomFieldEntityTrait IdentifierFieldEntityInterface and use CustomFieldEntityTrait inside that entity.
  • In this enttiy we also need to define relationships to other tables (how this custom table is connected to leads, companies, etc. tables - define PK & FKs)
  • Next we need to add entry to this form: app/bundles/LeadBundle/Form/Type/FieldType.php to show object in dropdown when we are creating new custom field.
  • Finally we need to modify this file: app\bundles\LeadBundle\Field\DTO\CustomFieldObject.php to include the object name that points to actual custom table in the database.

Everything mentionted above except the last point can one way or another be done via custom plugin.

So for modifications required in this file: app\bundles\LeadBundle\Field\DTO\CustomFieldObject.php I did not find any other way to modify it except changing the core file.

Would it be possible that this $objects variable inside the file above is somehow populated dynamically based on records in database. It can also be that CustomFieldObject.php file is somehow generated based on records in the database?

I think these groups of people would benefit from this idea:

Mautic Administrators.

Why I think they would benefit from this idea:

Well, with this solution we enable adding new objects to Mautic shipping this with Mautic core can be really powerful as you only need developer to define relationships between objects, fields can be added via user admins, whenever they please.

Any code or resources to support this idea:

I created a small demo for myself to check if registering new objects is possible.

Are you willing to work on this idea?:


What skills and resources do you need to explore this further?

Q1. If I decide to move forward and create a PR for this, would Mautic core team be open to merging that into the core (this kind of needs to be confirmed before hand, so I do not waste time on something that at the end does not get merged)?

Q2. Is there anything to watch out implementing this feature (any potential problems you see with my approach)?

Q3. Do you have any other suggestions in regards to this feature?

Thank you.

Regards, M.


The concern I have here is that the current custom field architecture does not scale. It creates new columns to database tables when a new custom field is created. It works nicely in a development environment but it is hell in production where you have thousands of queries running on that table per minute and the table is huge. So adding the column will lock the table that will add all the queries into a queue and they will start timing out which leads to data loss and bad user experience. In our experience, it will also cause the hit of the connection limit as so much queries are backed up and it can lead to the database server restart during the schema change and the database won’t be recoverable.

It has also other limits like number of indexed columns in a single table.

So I wouldn’t base a new feature on this bad architecture, but if you send a PR, I don’t see why it wouldn’t be merged if it won’t break anything.


It might be good to mention that there is also this custom objects plugin that might help someone reading this thread:

This is an interesting idea for sure. It’s easy to see how useful this could be, especially in the context of e-commerce and subscription membership platforms.

Also, I see what @escopecz is saying about the db tables. I ran an instance of Mautic once that maxed out the custom fields and it was a small disaster.

I wonder if new custom objects creation could come with a different structure that avoids the time out issue…


Thank you both for feedback.

About custom objects… While I really appreciate the plugin, I would advise anyone to really test the plugin before they decide to base a project on it (especially if a project is more complex).

About the max. number of cusom fields, I think this issue largely becomes less relevant with this feature since you can always just create a new object that is just extension of the previous one and connect it using FK.

Regards, M.