removeSection example

/** * {@inheritdoc} */
  public function getConfirmText() {
    return $this->t('Remove');
  }

  /** * {@inheritdoc} */
  protected function handleSectionStorage(SectionStorageInterface $section_storage, FormStateInterface $form_state) {
    $section_storage->removeSection($this->delta);
  }

}
/** * @covers ::removeSection */
  public function testRemoveSection() {
    $expected = [
      new Section('layout_test_plugin', ['setting_1' => 'bar'][
        '20000000-0000-1000-a000-000000000000' => new SectionComponent('20000000-0000-1000-a000-000000000000', 'content', ['id' => 'foo']),
      ]),
    ];

    $this->sectionList->removeSection(0);
    $this->assertSections($expected);
  }

  /** * @covers ::removeSection */
  public function testRemoveMultipleSections() {
    $expected = [
      new Section('layout_builder_blank'),
    ];

    

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

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

  /** * {@inheritdoc} */
  public function removeAllSections($set_blank = FALSE) {
    $this->getSectionList()->removeAllSections($set_blank);
    return $this;
  }

  
->save();

    $entity = EntityTest::create();
    $entity->set(OverridesSectionStorage::FIELD_NAME, [new Section('layout_onecol')]);
    $entity->save();
    $entity = EntityTest::load($entity->id());

    $context = EntityContext::fromEntity($entity);
    $this->plugin->setContext('entity', $context);

    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeSection(0);
    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeAllSections(TRUE);
    $this->assertTrue($this->plugin->isOverridden());
    $this->plugin->removeAllSections();
    $this->assertFalse($this->plugin->isOverridden());
  }

}
public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);

    // Loop through all sections and determine if the removed dependencies are     // used by their layout plugins.     foreach ($this->getSections() as $delta => $section) {
      $layout_dependencies = $this->getPluginDependencies($section->getLayout());
      $layout_removed_dependencies = $this->getPluginRemovedDependencies($layout_dependencies$dependencies);
      if ($layout_removed_dependencies) {
        // @todo Allow the plugins to react to their dependency removal in         // https://www.drupal.org/project/drupal/issues/2579743.         $this->removeSection($delta);
        $changed = TRUE;
      }
      // If the section is not removed, loop through all components.       else {
        foreach ($section->getComponents() as $uuid => $component) {
          $plugin_dependencies = $this->getPluginDependencies($component->getPlugin());
          $component_removed_dependencies = $this->getPluginRemovedDependencies($plugin_dependencies$dependencies);
          if ($component_removed_dependencies) {
            // @todo Allow the plugins to react to their dependency removal in             // https://www.drupal.org/project/drupal/issues/2579743.             $section->removeComponent($uuid);
            
Home | Imprint | This part of the site doesn't use cookies.