diff -u b/js/paragraphs.admin.js b/js/paragraphs.admin.js --- b/js/paragraphs.admin.js +++ b/js/paragraphs.admin.js @@ -16,7 +16,6 @@ } else { $('.paragraphs-content').hide(); - $('.paragraphs-nested.paragraphs-subform > .paragraphs-content').show(); $('.paragraphs-behavior').show(); } }, diff -u b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php --- b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php @@ -600,23 +600,38 @@ } if ($item_mode == 'edit') { - $element['subform']['paragraph_content'] = [ - '#type' => 'container', - '#attributes' => ['class' => ['paragraphs-content']] - ]; - $element['subform']['paragraph_behavior'] = [ - '#type' => 'container', - '#attributes' => ['class' => ['paragraphs-behavior']] - ]; $display->buildForm($paragraphs_entity, $element['subform'], $form_state); + // Get the field definitions of the paragraphs_entity. + // We need them to filter out entity reference revisions fields that + // reference paragraphs, cause otherwise we have problems with showing + // and hiding the right fields in nested paragraphs. + $field_definitions = $paragraphs_entity->getFieldDefinitions(); + foreach (Element::children($element['subform']) as $field) { + // Do a check if we have to add a class to the form element. We need + // those classes (paragraphs-content and paragraphs-behavior) to show + // and hide elements, depending of the active perspective. + $omit_class = FALSE; + if (isset($field_definitions[$field])) { + $type = $field_definitions[$field]->getType(); + if ($type == 'entity_reference_revisions') { + // Check if we are referencing paragraphs. + $target_entity_type = $field_definitions[$field]->get('entity_type'); + if ($target_entity_type && $target_entity_type == 'paragraph') { + $omit_class = TRUE; + } + } + } + if ($paragraphs_entity->hasField($field)) { - $element['subform'][$field]['#group'] = implode('][', array_merge($element_parents, ['paragraph_content'])); + if (!$omit_class) { + $element['subform'][$field]['#attributes']['class'][] = 'paragraphs-content'; + } $translatable = $paragraphs_entity->{$field}->getFieldDefinition()->isTranslatable(); if ($translatable) { $element['subform'][$field]['widget']['#after_build'][] = [ static::class, - 'removeTranslatabilityClue' + 'removeTranslatabilityClue', ]; } } @@ -631,6 +646,9 @@ '#group' => implode('][', array_merge($element_parents, ['paragraph_behavior'])), ]; $element['subform'][$plugin_id] += (array) $plugin->buildBehaviorForm($paragraphs_entity); + // Add the paragraphs-behavior class, so that we are able to show + // and hide behavior fields, depending on the active perspective. + $element['subform'][$plugin_id]['#attributes']['class'][] = 'paragraphs-behavior'; } } }