ContentTranslationHandler::entityFormEntityBuild

public ContentTranslationHandler::entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state)

Entity builder method.

Parameters

string $entity_type: The type of the entity.

\Drupal\Core\Entity\EntityInterface $entity: The entity whose form is being built.

See also

\Drupal\content_translation\ContentTranslationHandler::entityFormAlter()

File

core/modules/content_translation/src/ContentTranslationHandler.php, line 575

Class

ContentTranslationHandler
Base class for content translation handlers.

Namespace

Drupal\content_translation

Code

public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, FormStateInterface $form_state) {
  $form_object = $form_state->getFormObject();
  $form_langcode = $form_object->getFormLangcode($form_state);
  $values = &$form_state->getValue('content_translation', array());

  $metadata = $this->manager->getTranslationMetadata($entity);
  $metadata->setAuthor(!empty($values['uid']) ? User::load($values['uid']) : User::load(0));
  $metadata->setPublished(!empty($values['status']));
  $metadata->setCreatedTime(!empty($values['created']) ? strtotime($values['created']) : REQUEST_TIME);

  $source_langcode = $this->getSourceLangcode($form_state);
  if ($source_langcode) {
    $metadata->setSource($source_langcode);
  }

  $metadata->setOutdated(!empty($values['outdated']));
  if (!empty($values['retranslate'])) {
    $this->retranslate($entity, $form_langcode);
  }
}
doc_Drupal
2016-10-29 08:58:14
Comments
Leave a Comment

Please login to continue.