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:
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?