public function GridStackVariantForm::buildEntity in GridStack 8.2
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
- modules/
gridstack_ui/ src/ Form/ GridStackVariantForm.php, line 425
Class
- GridStackVariantForm
- Extends base form for gridstack instance configuration form.
Namespace
Drupal\gridstack_ui\FormCode
public function buildEntity(array $form, FormStateInterface $form_state) {
$entity = parent::buildEntity($form, $form_state);
$request = $this
->getRequest();
$request_uri = $request
->getRequestUri();
$source = $entity
->source();
if (empty($source)) {
if ($this->operation == 'add' || $this->operation == 'duplicate') {
$args = array_filter(explode('/', $request_uri));
// Given non-ajax URL: /admin/structure/gridstack...
if (isset($args[3]) && $args[3] == 'gridstack') {
// The last parameter is add or duplicate, remove.
array_pop($args);
$source = end($args);
if ($gridstack = GridStack::load($source)) {
$entity
->set('source', $source);
$this
->setGridStack($gridstack);
}
}
}
}
return $entity;
}