You are here

public function GeysirParagraphForm::save in Geysir 8

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

Overrides EntityForm::save

1 method overrides GeysirParagraphForm::save()
GeysirModalParagraphAddForm::save in src/Form/GeysirModalParagraphAddForm.php
Form submission handler for the 'save' action.

File

src/Form/GeysirParagraphForm.php, line 49

Class

GeysirParagraphForm
Functionality to edit a paragraph.

Namespace

Drupal\geysir\Form

Code

public function save(array $form, FormStateInterface $form_state) {
  $route_match = $this
    ->getRouteMatch();
  $parent_entity_type = $route_match
    ->getParameter('parent_entity_type');
  $parent_entity_revision = $route_match
    ->getParameter('parent_entity_revision');
  $field = $route_match
    ->getParameter('field');
  $delta = $route_match
    ->getParameter('delta');
  $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);
  $parent_entity_revision
    ->get($field)
    ->get($delta)
    ->setValue([
    'target_id' => $this->entity
      ->id(),
    'target_revision_id' => $this->entity
      ->getRevisionId(),
  ]);
  $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;
}