insertSection example


  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;
  }

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

  

  public function build(SectionStorageInterface $section_storage, int $delta$plugin_id) {
    $section_storage->insertSection($deltanew Section($plugin_id));

    $this->layoutTempstoreRepository->set($section_storage);

    if ($this->isAjax()) {
      return $this->rebuildAndClose($section_storage);
    }
    else {
      $url = $section_storage->getLayoutBuilderUrl();
      return new RedirectResponse($url->setAbsolute()->toString());
    }
  }

}
public function testInsertSection() {
    $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_onecol'),
      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->insertSection(1, new Section('layout_onecol'));
    $this->assertSections($expected);
  }

  /** * @covers ::appendSection */
  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']),
      ]),
      
// If this layout is context-aware, set the context mapping.     if ($this->layout instanceof ContextAwarePluginInterface) {
      $this->layout->setContextMapping($subform_state->getValue('context_mapping', []));
    }

    $configuration = $this->layout->getConfiguration();

    $section = $this->getCurrentSection();
    $section->setLayoutSettings($configuration);
    if (!$this->isUpdate) {
      $this->sectionStorage->insertSection($this->delta, $section);
    }

    $this->layoutTempstoreRepository->set($this->sectionStorage);
    $form_state->setRedirectUrl($this->sectionStorage->getLayoutBuilderUrl());
  }

  /** * {@inheritdoc} */
  protected function successfulAjaxSubmit(array $form, FormStateInterface $form_state) {
    return $this->rebuildAndClose($this->sectionStorage);
  }
Home | Imprint | This part of the site doesn't use cookies.