0

I am trying to programmatically create paragraphs using the Layout Paragraphs module. However, I'm encountering this error when saving the main entity that contains these paragraphs. I'm looking for guidance on the correct way to do this.

In SqlContentEntityStorage.php line 811: paragraph.ERROR: Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 139 of /var/www/app/core/lib/Drupal/Core/Entity/EntityTypeManager.php).

The code I am using is the following one.

foreach ($json_data as $key => $value) {
  $paragraph = Paragraph::create([
    'type' => 'main_products',
    'field_id' => $link['id'],
    'field_text' => $link['text'],
  ]);

  // Set the layout
  $layoutSettings = [
    'layout_paragraphs' => [
      'layout' => 'layout_fourcol_section',
      'config' => ['label' => ''],
      'parent_uuid' => null,
      'region' => null,
    ],
    'mega_menu_behavior' => []
  ];

  $paragraph->setBehaviorSettings('layout_paragraphs', $layoutSettings);
  $current[] = $paragraph;
}

$mainEntity = MegaMenuLayoutBuilder::create([
  'type' => 'mega_menu_layout_builder',
  'langcode' => $locale,
  'field_menu_items' => $paragraphs,
]);

$mainEntity->save();

What is the correct way to programmatically generate content for paragraphs using layout_paragraphs?

5
  • Is that code snippet your custom code, or is that part of Drupal itself?
    – cilefen
    Dec 1, 2023 at 19:27
  • @cilefen custom code, is a part of a drush command in a class to import the data from json and create the content into a custom entity, all working less the paragraphs with layout paragraphs Dec 1, 2023 at 19:41
  • What do you don't understand about the error message? Find the culprit getting an entity type definition with an empty string. Try xdebug or produce at least a full error message with stack trace.
    – 4uk4
    Dec 1, 2023 at 22:11
  • @4uk4 the entity is correct in the case of the paragraphs and the custom entity data, I really debug, the issue is related with layout_paragraphs, need something else. because to the normal paragraphs work correctly. Dec 1, 2023 at 22:57
  • OK, sometimes you can resolve this already if you enable full error messages with backtrace. See admin/config/development/logging. If not, then you need xdebug to check the variables why the entity type is an empty string.
    – 4uk4
    Dec 2, 2023 at 9:48

0

Your Answer

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

Browse other questions tagged or ask your own question.