public function LayoutBuilderStyleForm::buildEntity in Layout Builder Styles 8
Builds an updated entity object based upon the submitted form values.
For building the updated entity object the form's entity is cloned and the submitted form values are copied to entity properties. The form's entity remains unchanged.
Parameters
array $form: A nested array form elements comprising the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Entity\EntityInterface An updated copy of the form's entity object.
Overrides EntityForm::buildEntity
See also
\Drupal\Core\Entity\EntityFormInterface::getEntity()
File
- src/
Form/ LayoutBuilderStyleForm.php, line 202
Class
- LayoutBuilderStyleForm
- Class LayoutBuilderStyleForm.
Namespace
Drupal\layout_builder_styles\FormCode
public function buildEntity(array $form, FormStateInterface $form_state) {
$entity = parent::buildEntity($form, $form_state);
// We need to convert the individual checkbox values that were submitted
// in the form to a single array containing all the block plugin IDs that
// were checked.
$blockRestrictions = $form_state
->getValue('block_restrictions');
$blockRestrictions = array_keys(array_filter($blockRestrictions));
$entity
->set('block_restrictions', $blockRestrictions);
$layoutRestrictions = $form_state
->getValue('layout_restrictions');
$layoutRestrictions = array_keys(array_filter($layoutRestrictions));
$entity
->set('layout_restrictions', $layoutRestrictions);
return $entity;
}