getCurrentSection example



  /** * {@inheritdoc} */
  public function buildForm(array $form, FormStateInterface $form_state, SectionStorageInterface $section_storage = NULL, $delta = NULL, $plugin_id = NULL) {
    $this->sectionStorage = $section_storage;
    $this->delta = $delta;
    $this->isUpdate = is_null($plugin_id);
    $this->pluginId = $plugin_id;

    $section = $this->getCurrentSection();

    if ($this->isUpdate) {
      if ($label = $section->getLayoutSettings()['label']) {
        $form['#title'] = $this->t('Configure @section', ['@section' => $label]);
      }
    }
    // Passing available contexts to the layout plugin here could result in an     // exception since the layout may not have a context mapping for a required     // context slot on creation.     $this->layout = $section->getLayout();

    
public function getCurrentSection() {
    return $this->sectionStorage->getSection($this->delta);
  }

  /** * Retrieves the current component being edited by the form. * * @return \Drupal\layout_builder\SectionComponent * The current section component. */
  public function getCurrentComponent() {
    return $this->getCurrentSection()->getComponent($this->uuid);
  }

}
Home | Imprint | This part of the site doesn't use cookies.