public function EntityTranslationController::entityFormEntityBuild

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\translation_entity\EntityTranslationController::entityFormAlter()

1 call to EntityTranslationController::entityFormEntityBuild()
NodeTranslationController::entityFormEntityBuild in drupal/core/modules/node/lib/Drupal/node/NodeTranslationController.php
Overrides EntityTranslationController::entityFormEntityBuild().
1 method overrides EntityTranslationController::entityFormEntityBuild()
NodeTranslationController::entityFormEntityBuild in drupal/core/modules/node/lib/Drupal/node/NodeTranslationController.php
Overrides EntityTranslationController::entityFormEntityBuild().

File

drupal/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php, line 408
Definition of Drupal\translation_entity\EntityTranslationController.

Class

EntityTranslationController
Base class for entity translation controllers.

Namespace

Drupal\translation_entity

Code

public function entityFormEntityBuild($entity_type, EntityInterface $entity, array $form, array &$form_state) {
  $form_controller = translation_entity_form_controller($form_state);
  $form_langcode = $form_controller
    ->getFormLangcode($form_state);
  if (!isset($entity->translation[$form_langcode])) {
    $entity->translation[$form_langcode] = array();
  }
  $values = isset($form_state['values']['translation_entity']) ? $form_state['values']['translation_entity'] : array();
  $translation =& $entity->translation[$form_langcode];

  // @todo Use the entity setter when all entities support multilingual
  // properties.
  $translation['uid'] = !empty($values['name']) && ($account = user_load_by_name($values['name'])) ? $account->uid : 0;
  $translation['status'] = !empty($values['status']);
  $translation['created'] = !empty($values['created']) ? strtotime($values['created']) : REQUEST_TIME;
  $translation['changed'] = REQUEST_TIME;
  $source_langcode = $this
    ->getSourceLangcode($form_state);
  if ($source_langcode) {
    $translation['source'] = $source_langcode;
  }
  $translation['outdated'] = !empty($values['outdated']);
  if (!empty($values['retranslate'])) {
    $this
      ->retranslate($entity, $form_langcode);
  }

  // Set contextual information that can be reused during the storage phase.
  // @todo Remove this once we have an EntityLanguageDecorator to deal with
  //   the active language.
  $attributes = drupal_container()
    ->get('request')->attributes;
  $attributes
    ->set('working_langcode', $form_langcode);
  $attributes
    ->set('source_langcode', $source_langcode);
}