I'm in the middle of coding a custom entity in Drupal 8. Currently, I'm defining fields using the baseFieldDefinitions method. I've run into a small problem now where I have a subset of fields that need to be grouped together and repeatable. For example, I have a checkbox, a text box, and a select box that all need to be associated while allowing someone to click an "Add" button to produce another set of those three fields.
It seems that if I was using the UI to create a custom content type, then I could use Paragraphs to handle this, but I wasn't able to figure out how to do that in code, and all the modules that are used in Drupal 7 as example of how to do this either don't exist in D8, or point to using Paragraphs instead.
Some ideas that I had:
- Create all three as repeatable fields in baseFieldDefinitions and override the form to present them as a unit and write some ajax to make it work the way I want. I don't think this is ideal because it seems like I'm fighting the framework.
- Make this group of fields into their own entity and try to figure out how to add an entity creation form inside my parent entity creation form. I'm not sure if this is possible, but it seems like it should be.
- Use hook_schema to create a database table with the three fields that I need and an additional column to tie that record to my custom entity. This is the way I would have done it in Drupal 7, but I'm worried about the long term of running reports in Views using the data that isn't in the Entity itself. This seems like the quick and dirty way to do it but I don't want a Views headache later.
- Figure out how to do this in Paragraphs.
Hopefully, someone with a little more experience than I have in D8 can point me to the most preferable way to handle this. Any help would be greatly appreciated.