Loading src/LayoutParagraphsRendererService.php +3 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,9 @@ class LayoutParagraphsRendererService { /** * Renders a single Layout Paragraph Section for the provided paragraph. * * @param Drupal\paragraphs\Entity\Paragraph $paragraph * @param array $build * The build array. * @param \Drupal\paragraphs\Entity\Paragraph $paragraph * The paragraph entity. * @param string $view_mode * The view mode. Loading src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php +12 −10 Original line number Diff line number Diff line Loading @@ -42,26 +42,28 @@ class LayoutParagraphsFormatter extends EntityReferenceRevisionsEntityFormatter $entities = []; foreach ($items as $delta => $item) { // Ignore items where no entity could be loaded in prepareView() and // items that are not root level components. if (!empty($item->_loaded) && LayoutParagraphsComponent::isRootComponent($item->entity)) { // Ignore items where no entity could be loaded in prepareView(). if (!empty($item->_loaded)) { $entity = $item->entity; $access = $this->checkAccess($entity); // Add the access result's cacheability, ::view() needs it. $item->_accessCacheability = CacheableMetadata::createFromObject($access); if ($access->isAllowed()) { // Add the referring item, in case the formatter needs it. $entity->_referringItem = $items[$delta]; // Only include root level components. Nested components are rendered // by their parent respective containers. // @see Drupal\layout_paragraphs\LayoutParagraphsRendererService. if (LayoutParagraphsComponent::isRootComponent($item->entity)) { // Set the entity in the correct language for display. if ($entity instanceof TranslatableInterface) { $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $langcode); } // Add the referring item, in case the formatter needs it. $entity->_referringItem = $items[$delta]; $entities[$delta] = $entity; } } } } return $entities; } Loading tests/src/FunctionalJavascript/BuilderTestBase.php +7 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,13 @@ abstract class BuilderTestBase extends WebDriverTestBase { $button = $page->find('css', $css_selector); $button->click(); $this->assertSession()->assertWaitOnAjaxRequest(); $title = $page->find('css', '.ui-dialog-title'); if ($title->getText() == 'Choose a component') { $page->clickLink('text'); $this->assertSession()->assertWaitOnAjaxRequest(); } $this->assertSession()->pageTextContains('field_text'); $page->fillField('field_text[0][value]', $text); Loading tests/src/FunctionalJavascript/NestedSectionsTest.php 0 → 100644 +86 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\Core\Entity\Entity\EntityFormDisplay; /** * Tests nested sections including the node preview screen. * * @group layout_paragraphs */ class NestedSectionsTest extends BuilderTestBase { /** * {@inheritDoc} */ protected function setUp(): void { parent::setUp(); // Allow nesting sections. $entity_form_display = EntityFormDisplay::load('node.page.default'); $component = $entity_form_display->getComponent('field_content'); $component['settings']['nesting_depth'] = 1; $entity_form_display ->setComponent('field_content', $component) ->save(); } /** * Tests nested sections. */ public function testNestedSections() { $this->loginWithPermissions([ 'create page content', 'edit own page content', ]); $this->drupalGet('node/add/page'); $page = $this->getSession()->getPage(); // Add a two-column section. $this->addSectionComponent(1, '.lpb-btn--add'); // Add a one-column section in region 1. $this->addSectionComponent(0, '.layout__region--first .lpb-btn--add'); // Add a three-column section in region 2. $this->addSectionComponent(2, '.layout__region--second .lpb-btn--add'); // Add a text component in each nested section. $this->addTextComponent('First', '.layout__region--first .layout__region--content .lpb-btn--add'); $this->addTextComponent('Second', '.layout__region--second .layout__region--first .lpb-btn--add'); $this->addTextComponent('Third', '.layout__region--second .layout__region--second .lpb-btn--add'); $this->addTextComponent('Fourth', '.layout__region--second .layout__region--third .lpb-btn--add'); // Preview the node. $this->submitForm([ 'title[0][value]' => 'Node title', ], 'Preview'); // Check for all the added components. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); // Back to editing. $this->clickLink('Back to content editing'); // Check for all the added components still on edit tab. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); // Save the node. $this->submitForm([ 'title[0][value]' => 'Node title', ], 'Save'); // Check for all the added components still on view tab. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); } } Loading
src/LayoutParagraphsRendererService.php +3 −1 Original line number Diff line number Diff line Loading @@ -48,7 +48,9 @@ class LayoutParagraphsRendererService { /** * Renders a single Layout Paragraph Section for the provided paragraph. * * @param Drupal\paragraphs\Entity\Paragraph $paragraph * @param array $build * The build array. * @param \Drupal\paragraphs\Entity\Paragraph $paragraph * The paragraph entity. * @param string $view_mode * The view mode. Loading
src/Plugin/Field/FieldFormatter/LayoutParagraphsFormatter.php +12 −10 Original line number Diff line number Diff line Loading @@ -42,26 +42,28 @@ class LayoutParagraphsFormatter extends EntityReferenceRevisionsEntityFormatter $entities = []; foreach ($items as $delta => $item) { // Ignore items where no entity could be loaded in prepareView() and // items that are not root level components. if (!empty($item->_loaded) && LayoutParagraphsComponent::isRootComponent($item->entity)) { // Ignore items where no entity could be loaded in prepareView(). if (!empty($item->_loaded)) { $entity = $item->entity; $access = $this->checkAccess($entity); // Add the access result's cacheability, ::view() needs it. $item->_accessCacheability = CacheableMetadata::createFromObject($access); if ($access->isAllowed()) { // Add the referring item, in case the formatter needs it. $entity->_referringItem = $items[$delta]; // Only include root level components. Nested components are rendered // by their parent respective containers. // @see Drupal\layout_paragraphs\LayoutParagraphsRendererService. if (LayoutParagraphsComponent::isRootComponent($item->entity)) { // Set the entity in the correct language for display. if ($entity instanceof TranslatableInterface) { $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $langcode); } // Add the referring item, in case the formatter needs it. $entity->_referringItem = $items[$delta]; $entities[$delta] = $entity; } } } } return $entities; } Loading
tests/src/FunctionalJavascript/BuilderTestBase.php +7 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,13 @@ abstract class BuilderTestBase extends WebDriverTestBase { $button = $page->find('css', $css_selector); $button->click(); $this->assertSession()->assertWaitOnAjaxRequest(); $title = $page->find('css', '.ui-dialog-title'); if ($title->getText() == 'Choose a component') { $page->clickLink('text'); $this->assertSession()->assertWaitOnAjaxRequest(); } $this->assertSession()->pageTextContains('field_text'); $page->fillField('field_text[0][value]', $text); Loading
tests/src/FunctionalJavascript/NestedSectionsTest.php 0 → 100644 +86 −0 Original line number Diff line number Diff line <?php namespace Drupal\Tests\layout_paragraphs\FunctionalJavascript; use Drupal\Core\Entity\Entity\EntityFormDisplay; /** * Tests nested sections including the node preview screen. * * @group layout_paragraphs */ class NestedSectionsTest extends BuilderTestBase { /** * {@inheritDoc} */ protected function setUp(): void { parent::setUp(); // Allow nesting sections. $entity_form_display = EntityFormDisplay::load('node.page.default'); $component = $entity_form_display->getComponent('field_content'); $component['settings']['nesting_depth'] = 1; $entity_form_display ->setComponent('field_content', $component) ->save(); } /** * Tests nested sections. */ public function testNestedSections() { $this->loginWithPermissions([ 'create page content', 'edit own page content', ]); $this->drupalGet('node/add/page'); $page = $this->getSession()->getPage(); // Add a two-column section. $this->addSectionComponent(1, '.lpb-btn--add'); // Add a one-column section in region 1. $this->addSectionComponent(0, '.layout__region--first .lpb-btn--add'); // Add a three-column section in region 2. $this->addSectionComponent(2, '.layout__region--second .lpb-btn--add'); // Add a text component in each nested section. $this->addTextComponent('First', '.layout__region--first .layout__region--content .lpb-btn--add'); $this->addTextComponent('Second', '.layout__region--second .layout__region--first .lpb-btn--add'); $this->addTextComponent('Third', '.layout__region--second .layout__region--second .lpb-btn--add'); $this->addTextComponent('Fourth', '.layout__region--second .layout__region--third .lpb-btn--add'); // Preview the node. $this->submitForm([ 'title[0][value]' => 'Node title', ], 'Preview'); // Check for all the added components. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); // Back to editing. $this->clickLink('Back to content editing'); // Check for all the added components still on edit tab. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); // Save the node. $this->submitForm([ 'title[0][value]' => 'Node title', ], 'Save'); // Check for all the added components still on view tab. $this->assertSession()->pageTextContains('First'); $this->assertSession()->pageTextContains('Second'); $this->assertSession()->pageTextContains('Third'); $this->assertSession()->pageTextContains('Fourth'); } }