appendSection example

/** * {@inheritdoc} */
  public function getSection($delta) {
    return $this->getSectionList()->getSection($delta);
  }

  /** * {@inheritdoc} */
  public function appendSection(Section $section) {
    $this->getSectionList()->appendSection($section);
    return $this;
  }

  /** * {@inheritdoc} */
  public function insertSection($delta, Section $section) {
    $this->getSectionList()->insertSection($delta$section);
    return $this;
  }

  
    if ($this->hasBlankSection()) {
      $this->removeAllSections();
    }

    if ($this->hasSection($delta)) {
      // @todo Use https://www.drupal.org/node/66183 once resolved.       $start = array_slice($this->getSections(), 0, $delta);
      $end = array_slice($this->getSections()$delta);
      $this->setSections(array_merge($start[$section]$end));
    }
    else {
      $this->appendSection($section);
    }
    return $this;
  }

  /** * Adds a blank section to the list. * * @return $this * * @see \Drupal\layout_builder\Plugin\Layout\BlankLayout */
  


  /** * Gets a default section. * * @return \Drupal\layout_builder\Section * The default section. */
  protected function getDefaultSection() {
    // If no section exists, append a new one.     if (!$this->hasSection(0)) {
      $this->appendSection(new Section('layout_onecol'));
    }

    // Return the first section.     return $this->getSection(0);
  }

  /** * Gets the section storage manager. * * @return \Drupal\layout_builder\SectionStorage\SectionStorageManagerInterface * The section storage manager. */
$entity = $context['entity'];

      // Node 1 or 2: Append a block to the layout.       if (in_array($entity->id()['1', '2'])) {
        $section = new Section('layout_onecol');
        $section->appendComponent(new SectionComponent('fake-uuid', 'content', [
          'id' => 'static_block',
          'label' => 'Test static block title',
          'label_display' => 'visible',
          'provider' => 'fake_provider',
        ]));
        $section_storage->appendSection($section);
      }

      // Node 2: Stop event propagation.       if ($entity->id() === '2') {
        $event->stopPropagation();
      }
    }
  }

  /** * Subscriber to test acting after the LB subscriber. * * @param \Drupal\layout_builder\Event\PrepareLayoutEvent $event * The prepare layout event. */
public function testAppendSection() {
    $expected = [
      new Section('layout_test_plugin', ['setting_1' => 'Default'][
        '10000000-0000-1000-a000-000000000000' => new SectionComponent('10000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
      new Section('layout_test_plugin', ['setting_1' => 'bar'][
        '20000000-0000-1000-a000-000000000000' => new SectionComponent('20000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
      new Section('layout_onecol'),
    ];

    $this->sectionList->appendSection(new Section('layout_onecol'));
    $this->assertSections($expected);
  }

  /** * @covers ::removeAllSections * * @dataProvider providerTestRemoveAllSections */
  public function testRemoveAllSections($set_blank$expected) {
    if ($set_blank === NULL) {
      $this->sectionList->removeAllSections();
    }
// If the layout has pending changes, add a warning.     if ($this->layoutTempstoreRepository->has($section_storage)) {
      $this->messenger->addWarning($this->t('You have unsaved changes.'));
    }
    else {
      // If the layout is an override that has not yet been overridden, copy the       // sections from the corresponding default.       if ($section_storage instanceof OverridesSectionStorageInterface && !$section_storage->isOverridden()) {
        $sections = $section_storage->getDefaultSectionStorage()->getSections();
        foreach ($sections as $section) {
          $section_storage->appendSection($section);
        }
      }
      // Add storage to tempstore regardless of what the storage is.       $this->layoutTempstoreRepository->set($section_storage);
    }
  }

}
$this->assertEmpty($this->cssSelect('.layout__region .field--name-test-display-non-configurable'));

    $this->installLayoutBuilder();

    // Without using Layout Builder for an override, the result has not changed.     $this->assertFieldAttributes($this->entity, $expected_fields);

    // Add a layout override.     $this->enableOverrides();
    /** @var \Drupal\layout_builder\SectionStorageInterface $field_list */
    $field_list = $this->entity->get(OverridesSectionStorage::FIELD_NAME);
    $field_list->appendSection(new Section('layout_onecol'));
    $this->entity->save();

    // The rendered entity has now changed. The non-configurable field is shown     // outside the layout, the configurable field is not shown at all, and the     // layout itself is rendered (but empty).     $new_expected_fields = [
      'field field--name-name field--type-string field--label-hidden field__item',
      'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
      'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
    ];
    $this->assertFieldAttributes($this->entity, $new_expected_fields);
    

    $this->assertFieldAttributes($this->entity, $expected_fields);

    $this->installLayoutBuilder();

    // Without using Layout Builder for an override, the result has not changed.     $this->assertFieldAttributes($this->entity, $expected_fields);

    // Add a layout override.     $this->enableOverrides();
    $this->entity = $this->reloadEntity($this->entity);
    $this->entity->get(OverridesSectionStorage::FIELD_NAME)->appendSection(new Section('layout_onecol'));
    $this->entity->save();

    // The rendered entity has now changed. The non-configurable field is shown     // outside the layout, the configurable field is not shown at all, and the     // layout itself is rendered (but empty).     $new_expected_fields = [
      'field field--name-name field--type-string field--label-hidden field__item',
      'clearfix text-formatted field field--name-test-display-non-configurable field--type-text field--label-above',
      'clearfix text-formatted field field--name-test-display-multiple field--type-text field--label-above',
    ];
    $this->assertFieldAttributes($this->entity, $new_expected_fields);
    
Home | Imprint | This part of the site doesn't use cookies.