public function GeysirModalParagraphAddForm::save in Geysir 8
Throws
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
\Drupal\Component\Plugin\Exception\PluginNotFoundException
\Drupal\Core\Entity\EntityStorageException
Overrides GeysirParagraphForm::save
File
- src/
Form/ GeysirModalParagraphAddForm.php, line 24
Class
- GeysirModalParagraphAddForm
- Functionality to edit a paragraph through a modal.
Namespace
Drupal\geysir\FormCode
public function save(array $form, FormStateInterface $form_state) {
$route_match = $this
->getRouteMatch();
$parent_entity_type = $route_match
->getParameter('parent_entity_type');
$temporary_data = $form_state
->getTemporary();
$parent_entity_revision = isset($temporary_data['parent_entity_revision']) ? $temporary_data['parent_entity_revision'] : $route_match
->getParameter('parent_entity_revision');
$this->entity
->setNewRevision(TRUE);
$this->entity
->save();
// Get the parent revision if available, otherwise the parent.
$parent_entity_revision = $this
->getParentRevisionOrParent($parent_entity_type, $parent_entity_revision);
// If we add the first paragraph, no need for reordering.
if (!empty($route_match
->getParameter('paragraph'))) {
$this
->reorderItemList($parent_entity_revision);
}
else {
$this
->insertFirstItem($parent_entity_revision);
}
$save_status = $this
->saveParentEntityRevision($parent_entity_revision, $this->time, $this
->currentUser());
// Use the parent revision id if available, otherwise the parent id.
$parent_revision_id = $parent_entity_revision
->getRevisionId() ? $parent_entity_revision
->getRevisionId() : $parent_entity_revision
->id();
$form_state
->setTemporary([
'parent_entity_revision' => $parent_revision_id,
]);
return $save_status;
}