Account created on 10 September 2012, over 12 years ago
#

Recent comments

🇨🇦Canada jorgediazhav

I did a workaround for this, as described here: https://www.drupal.org/project/default_content/issues/3329816#comment-16... Layout Paragraphs Support Active

🇨🇦Canada jorgediazhav

I found a workaround for this, and I hope it somehow gives an insight for possible solutions.

I have a node with a paragraph reference field (LVL1) that then has a field reference that aims towards other paragraphs (LVL2). The problem was, as stated before by @nicholass , the LVL 2 paragraphs are mot being exported.

The structure is somehow like this:

Node
------> Paragraph LVL 1
---------------> Paragraph LVL 2 #1
---------------> Paragraph LVL 2 #2

The workaround:

First, I export a node like this:

drush dcer node NODE_ID --folder=../recipes/RECIPE_NAME

Then, I run the following in the command line to identify all the paragraphs IDs that are referenced in LVL2:

drush php-eval '
$node = \Drupal\node\Entity\Node::load(NODE_ID);
$nested_ids = [];

// Loop through first-level paragraphs.
foreach ($node->get("field_PARAGRAPHS_LVL1")->referencedEntities() as $paragraph) {
    if ($paragraph->hasField("field_PARAGRAPHS_LVL2")) {
        foreach ($paragraph->get("field_PARAGRAPHS_LVL2")->referencedEntities() as $nested) {
            $nested_ids[] = $nested->id();
        }
    }
}

// Remove duplicates
$nested_ids = array_unique($nested_ids);
sort($nested_ids);

// Export commands
foreach ($nested_ids as $id) {
    echo "drush dcer paragraph $id --folder=../recipes/RECIPE_NAME\n";
}
'

This will generate a list of commands like this (with the respective LVL2 paragraph IDs):

drush dcer paragraph 24693 --folder=../recipes/RECIPE_NAME 
drush dcer paragraph 24694 --folder=../recipes/RECIPE_NAME 
drush dcer paragraph 24695 --folder=../recipes/RECIPE_NAME 
drush dcer paragraph 24696 --folder=../recipes/RECIPE_NAME

Then, by running those commands, all paragraphs get generated under the RECIPE_NAME/paragraph/ folder.

Then, importing will work (paragraphs will be created and properly referenced from the LVL1 paragraph and the Node). The problem is actually occurs during the export.

Hope it helps!

Production build 0.71.5 2024