protected function FieldLayoutEntityDisplayFormTrait::getLayout in Drupal 10
Same name and namespace in other branches
- 8 core/modules/field_layout/src/Form/FieldLayoutEntityDisplayFormTrait.php \Drupal\field_layout\Form\FieldLayoutEntityDisplayFormTrait::getLayout()
- 9 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.
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;
}