setLayout example


  public function submitForm(array &$form, FormStateInterface $form_state) {
    parent::submitForm($form$form_state);

    $entity = $this->getEntity();
    $layout_plugin = $this->getLayout($entity$form_state);
    if ($layout_plugin instanceof PluginFormInterface) {
      $subform_state = SubformState::createForSubform($form['field_layouts']['settings_wrapper']['layout_settings']$form$form_state);
      $layout_plugin->submitConfigurationForm($form['field_layouts']['settings_wrapper']['layout_settings']$subform_state);
    }

    $entity->setLayout($layout_plugin);
  }

  /** * Gets the form entity. * * @return \Drupal\field_layout\Display\EntityDisplayWithLayoutInterface * The current form entity. */
  abstract public function getEntity();

}
/** * Overrides \Drupal\Core\Entity\EntityDisplayBase::preSave(). */
  public function preSave(EntityStorageInterface $storage) {
    parent::preSave($storage);

    // Ensure the plugin configuration is updated. Once layouts are no longer     // stored as third party settings, this will be handled by the code in     // \Drupal\Core\Config\Entity\ConfigEntityBase::preSave() that handles     // \Drupal\Core\Entity\EntityWithPluginCollectionInterface.     if ($this->getLayoutId()) {
      $this->setLayout($this->getLayout());
    }
  }

  /** * {@inheritdoc} */
  public function ensureLayout($default_layout_id = 'layout_onecol') {
    if (!$this->getLayoutId()) {
      $this->setLayoutId($default_layout_id);
    }

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