0

can Someone explain how can i make one field in Drupal 8 that can contain multiple fields in it... I am not allowed to use Paragraph module. I want to make it full programmatically, By the way i know how to make simple field in Drupal 8 but don't know how to set schema or form form dynamic field that can have multiple fields in it. For Example when we want to add some field in user or in node, we go to ~/fields/add-field and then select the field type, after in the field setting i want to have one form element that says add filed and the type of the field. and after saving setting, i will generate the field widget and formater depending on the field type selection that i made before.

Is there a solution for this problem (only programmatically)?

7
  • 1
    You're best off just using Paragraphs or Field Collections where the problem is already solved.
    – Kevin
    Commented Aug 7, 2017 at 15:11
  • Thank you @kevin but i can't use this modules... only programmatically Commented Aug 7, 2017 at 15:13
  • If you just need a compound field Paragraphs and Field Collection (especially) are probably unnecessary overhead. Have a look at how the core text fields work, they have multiple columns and multiple form elements. For example: api.drupal.org/api/drupal/…
    – Clive
    Commented Aug 7, 2017 at 15:16
  • thanks Clive but that way it has to be predefined, i want something more dynamic Commented Aug 7, 2017 at 15:19
  • What do you mean by "dynamic" exactly? The schema has to be predefined, it's responsible for which columns get added to the table that stores the data
    – Clive
    Commented Aug 7, 2017 at 15:19

2 Answers 2

0

If you prefer another approach, a little more clean and following the Drupal structure, you can use Inline Entity Form to do that.

I don't like Paragraphs and Field Collection for just one reason. They don't follow the way that Drupal storages data in DB. If you open your database and search for the tables that this modules create, you will be able to see some strange patterns.

https://www.drupal.org/project/inline_entity_form

3
  • 1
    "you will be able to see some strange patterns." No idea what makes you think that. There are no strange patterns with paragraphs. IEF and paragraphs is exactly the same, just a different widget. Both use entity reference (entity reference revisions in case of paragraphs because that is the only way that embedded entities with revisions work) and separate entities to store the data. Paragraphs provides its own type that is optimized for embedded and also works well with e.g. previews, with IEF you need to use an existing entity type.
    – Berdir
    Commented Aug 7, 2017 at 17:55
  • That doesn't mean that you can't use IEF, I just disagree with the argumentation. Try both, use what makes more sense for your use case. IEF is more optimized towards re-using existing entities and not too specifically optimized for content-building like the paragraphs widget is, especially with the improvements we're working on in the experimental widget with drag and drop, duplicating, summaries and so on.
    – Berdir
    Commented Aug 7, 2017 at 17:58
  • "Paragraphs provides its own type that is optimized for embedded and also works well with e.g. previews, with IEF you need to use an existing entity type.". That is exactly the problem for me. I've been faced some troubles with that custom type, especial with some relationships in views. And I agree too, that work with IEF is a little more difficult, but prevents this kind of problem. Commented Aug 8, 2017 at 1:28
0

Content Entity Builder module: https://www.drupal.org/project/content_entity_builder

Allow you add multiple base field to entity by config. it store all base fields in one table.

If you don't like the way : one field 2 tables. You can have a try with this module.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.