You are here

public function FieldCollectionItemForm::submitForm in Field collection 8

Same name and namespace in other branches
  1. 8.3 src/FieldCollectionItemForm.php \Drupal\field_collection\FieldCollectionItemForm::submitForm()

This is the default entity object builder function. It is called before any other submit handler to build the new entity object to be used by the following submit handlers. At this point of the form workflow the entity is validated and the form state can be updated, this way the subsequently invoked handlers can retrieve a regular entity object to act on. Generally this method should not be overridden unless the entity requires the same preparation for two actions, see \Drupal\comment\CommentForm for an example with the save and preview actions.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Overrides ContentEntityForm::submitForm

File

src/FieldCollectionItemForm.php, line 52

Class

FieldCollectionItemForm

Namespace

Drupal\field_collection

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Build the block object from the submitted values.
  parent::submitForm($form, $form_state);
  $field_collection_item = $this->entity;

  // TODO: Create new revision every edit?  Might be better to make it an
  // option.  In either case, it doesn't work as is.  The default
  // revision of the host isn't getting updated to point to the new
  // field collection item revision.
  // $field_collection_item->setNewRevision();
  $route_match = \Drupal::routeMatch();
  if ($route_match
    ->getRouteName() == 'field_collection_item.add_page') {
    $host = $this->entityTypeManager
      ->getStorage($route_match
      ->getParameter('host_type'))
      ->load($route_match
      ->getParameter('host_id'));
  }
  else {
    $host = $field_collection_item
      ->getHost();
  }
  $form_state
    ->setRedirectUrl($host
    ->toUrl());
}