Error when Programmatically Creating Paragraphs with Layout Paragraphs Settings

Created on 1 December 2023, 7 months ago

Description:

I am encountering an error when trying to programmatically create paragraphs and apply layout settings using the layout_paragraphs module. The error occurs when I attempt to save the main entity that contains the paragraphs.

Error Message:

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).

Code to Reproduce:

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 = CustomEntityLayoutBuilder::create([
'type' => 'custom_entity_layout_builder',
'langcode' => $locale,
'field_menu_items' => $paragraphs,
]);
$mainEntity->save();

Expected Behavior:

The paragraphs should be created with the specified layout settings and saved without any errors.

Actual Behavior:

An error is thrown indicating a problem with the entity type definition when trying to save the main entity.

Steps to Reproduce:

  1. Use the provided code snippet to create paragraphs with layout settings.
  2. Attempt to save the main entity containing these paragraphs.

Additional Information:

  • Drupal version: Drupal 9
  • Layout Paragraphs module version: 2.0.3

Question:

What is the correct way to programmatically generate content for paragraphs using layout_paragraphs? Any guidance or suggestions to resolve this error would be greatly appreciated.

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States yorchperaza Denver

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

Comments & Activities

Production build 0.69.0 2024