class LayoutBuilderWidget
Same name and namespace in other branches
- 11.x core/modules/layout_builder/src/Plugin/Field/FieldWidget/LayoutBuilderWidget.php \Drupal\layout_builder\Plugin\Field\FieldWidget\LayoutBuilderWidget
- 10 core/modules/layout_builder/src/Plugin/Field/FieldWidget/LayoutBuilderWidget.php \Drupal\layout_builder\Plugin\Field\FieldWidget\LayoutBuilderWidget
- 8.9.x core/modules/layout_builder/src/Plugin/Field/FieldWidget/LayoutBuilderWidget.php \Drupal\layout_builder\Plugin\Field\FieldWidget\LayoutBuilderWidget
A widget to display the layout form.
@FieldWidget( id = "layout_builder_widget", label = @Translation("Layout Builder Widget"), description = @Translation("A field widget for Layout Builder."), field_types = { "layout_section", }, multiple_values = TRUE, )
@internal Plugin classes are internal.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Field\WidgetBase implements \Drupal\Core\Field\WidgetInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\layout_builder\Plugin\Field\FieldWidget\LayoutBuilderWidget extends \Drupal\Core\Field\WidgetBase
- class \Drupal\Core\Field\WidgetBase implements \Drupal\Core\Field\WidgetInterface, \Drupal\Core\Plugin\ContainerFactoryPluginInterface extends \Drupal\Core\Field\PluginSettingsBase
- class \Drupal\Core\Field\PluginSettingsBase implements \Drupal\Core\Field\PluginSettingsInterface, \Drupal\Component\Plugin\DependentPluginInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of LayoutBuilderWidget
File
-
core/
modules/ layout_builder/ src/ Plugin/ Field/ FieldWidget/ LayoutBuilderWidget.php, line 25
Namespace
Drupal\layout_builder\Plugin\Field\FieldWidgetView source
class LayoutBuilderWidget extends WidgetBase {
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element += [
'#type' => 'layout_builder',
'#section_storage' => $this->getSectionStorage($form_state),
];
$element['#process'][] = [
static::class,
'layoutBuilderElementGetKeys',
];
return $element;
}
/**
* Form element #process callback.
*
* Save the layout builder element array parents as a property on the top form
* element so that they can be used to access the element within the whole
* render array later.
*
* @see \Drupal\layout_builder\Controller\LayoutBuilderHtmlEntityFormController
*/
public static function layoutBuilderElementGetKeys(array $element, FormStateInterface $form_state, &$form) {
$form['#layout_builder_element_keys'] = $element['#array_parents'];
return $element;
}
/**
* {@inheritdoc}
*/
public function extractFormValues(FieldItemListInterface $items, array $form, FormStateInterface $form_state) {
// @todo This isn't resilient to being set twice, during validation and
// save https://www.drupal.org/project/drupal/issues/2833682.
if (!$form_state->isValidationComplete()) {
return;
}
$items->setValue($this->getSectionStorage($form_state)
->getSections());
}
/**
* Gets the section storage.
*
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*
* @return \Drupal\layout_builder\SectionStorageInterface
* The section storage loaded from the tempstore.
*/
private function getSectionStorage(FormStateInterface $form_state) {
return $form_state->getFormObject()
->getSectionStorage();
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.