function FieldLayoutEntityDisplayFormTrait::getLayout
Same name in other branches
- 9 core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::getLayout()
- 8.9.x core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::getLayout()
- 11.x core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::getLayout()
Gets the layout plugin for the currently selected field layout.
Parameters
\Drupal\field_layout\Display\EntityDisplayWithLayoutInterface $entity: The current form entity.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Layout\LayoutInterface The layout plugin.
3 calls to FieldLayoutEntityDisplayFormTrait::getLayout()
- FieldLayoutEntityDisplayFormTrait::form in core/
modules/ field_layout/ src/ Form/ FieldLayoutEntityDisplayFormTrait.php - Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::form().
- FieldLayoutEntityDisplayFormTrait::submitForm in core/
modules/ field_layout/ src/ Form/ FieldLayoutEntityDisplayFormTrait.php - Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::submitForm().
- FieldLayoutEntityDisplayFormTrait::validateForm in core/
modules/ field_layout/ src/ Form/ FieldLayoutEntityDisplayFormTrait.php - Overrides \Drupal\field_ui\Form\EntityDisplayFormBase::validateForm().
File
-
core/
modules/ field_layout/ src/ Form/ FieldLayoutEntityDisplayFormTrait.php, line 112
Class
- FieldLayoutEntityDisplayFormTrait
- Provides shared code for entity display forms.
Namespace
Drupal\field_layout\FormCode
protected function getLayout(EntityDisplayWithLayoutInterface $entity, FormStateInterface $form_state) {
if (!($layout_plugin = $form_state->get('layout_plugin'))) {
$stored_layout_id = $entity->getLayoutId();
// Use selected layout if it exists, falling back to the stored layout.
$layout_id = $form_state->getValue('field_layout', $stored_layout_id);
// If the current layout is the stored layout, use the stored layout
// settings. Otherwise leave the settings empty.
$layout_settings = $layout_id === $stored_layout_id ? $entity->getLayoutSettings() : [];
$layout_plugin = $this->layoutPluginManager
->createInstance($layout_id, $layout_settings);
$form_state->set('layout_plugin', $layout_plugin);
}
return $layout_plugin;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.