Any way / plans to create nested entities / content

Created on 3 November 2022, about 2 years ago
Updated 27 April 2024, 8 months ago

We have quite complex, nested content types consisting of paragraphs which can themselves contain paragraphs.

A node consists of a paragraph as a header in which the type is defined, e.g. press, event, etc., and a content area which in turn can contain further paragraphs such as lists, image galleries and the like.

We would now like to create a form for event registration that automatically creates event nodes. But since our node is just the shell for a lot of paragraphs, we can't get there with the Webform Content Creator.

Is there an idea or plan how to realize something like this without programming it again and again for every new form?

Feature request
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

🇩🇪Germany macdev_drupal Wiesbaden

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇫🇮Finland tvalimaa

    I have same issue that content type is using paragraphs. I think it's just easier and fastest just create custom module and use this module code base for some help. Basic idea is just use webform submission hook and tigger own custom function to create node programmatically without any UI mapping or settings. Other thing what I can do is extend this module code and override mapping part but maybe simple submission hook + custom node creating is fastest.

  • 🇩🇪Germany jocowood Kamp-Lintfort

    Hey tvalimaa, I think your approach is very good. It contains only a few errors, which I have corrected. In addition, the method signature of mapEntityField has changed. I have adjusted that as well. Please excuse that I am more a fan of the snakecase :-)

    /**
       * {@inheritdoc}
       */
      public function mapEntityField(ContentEntityInterface &$content, array $webform_element, FieldDefinitionInterface $field_definition, array $data = [], array $attributes = []) {
        $fieldId = $field_definition->getName();
        $paragraphFieldValue = $data[$fieldId];
    
        if (!empty($paragraphFieldValue)) {
          $paragraph = Paragraph::create([
            'type' => 'text',
            'field_text' => [
              'value' => $paragraphFieldValue,
              'format' => 'full_html'
            ],
          ]);
          $paragraph->save();
    
          $fieldValue[] = [
            'target_id' => $paragraph->id(),
            'target_revision_id' => $paragraph->getRevisionId(),
          ];
          $content->set($fieldId, $fieldValue);
        }
      }
  • 🇵🇹Portugal joaomarques736

    Hello all,

    Considering the new plugin system, it can be extended to create the plugins for any type of complex field, including paragraphs.

    Best regards.

  • Status changed to Closed: works as designed 8 months ago
Production build 0.71.5 2024