You are here

function ContentTranslationHandler::entityFormSubmit in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/content_translation/src/ContentTranslationHandler.php \Drupal\content_translation\ContentTranslationHandler::entityFormSubmit()

Form submission handler for ContentTranslationHandler::entityFormAlter().

Updates metadata fields, which should be updated only after the validation has run and before the entity is saved.

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 626
Contains \Drupal\content_translation\ContentTranslationHandler.

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

function entityFormSubmit($form, FormStateInterface $form_state) {

  /** @var \Drupal\Core\Entity\ContentEntityFormInterface $form_object */
  $form_object = $form_state
    ->getFormObject();

  /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
  $entity = $form_object
    ->getEntity();

  // ContentEntityForm::submit will update the changed timestamp on submit
  // after the entity has been validated, so that it does not break the
  // EntityChanged constraint validator. The content translation metadata
  // field for the changed timestamp  does not have such a constraint defined
  // at the moment, but it is correct to update it's value in a submission
  // handler as well and have the same logic like in the Form API.
  if ($entity
    ->hasField('content_translation_changed')) {
    $metadata = $this->manager
      ->getTranslationMetadata($entity);
    $metadata
      ->setChangedTime(REQUEST_TIME);
  }
}