You are here

public function DashboardLayoutBuilderForm::buildEntity in Dashboards with Layout Builder 8

Same name and namespace in other branches
  1. 2.0.x src/Form/DashboardLayoutBuilderForm.php \Drupal\dashboards\Form\DashboardLayoutBuilderForm::buildEntity()

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/DashboardLayoutBuilderForm.php, line 165

Class

DashboardLayoutBuilderForm
DashboardLayoutBuilderForm class.

Namespace

Drupal\dashboards\Form

Code

public function buildEntity(array $form, FormStateInterface $form_state) {

  // \Drupal\Core\Entity\EntityForm::buildEntity() clones the entity object.
  // Keep it in sync with the one used by the section storage.
  $entity = $this->sectionStorage
    ->getContextValue(Dashboard::CONTEXT_TYPE);
  $entity->isOverriden = TRUE;
  $this
    ->setEntity($this->sectionStorage
    ->getContextValue(Dashboard::CONTEXT_TYPE));
  $entity = parent::buildEntity($form, $form_state);
  $this->sectionStorage
    ->setContextValue(Dashboard::CONTEXT_TYPE, $entity);
  return $entity;
}