You are here

public function EntityTranslationDefaultHandler::entityFormSubmit in Entity Translation 7

Overrides EntityTranslationHandlerInterface::entityFormSubmit

See also

EntityTranslationHandlerInterface::entityFormSubmit()

1 call to EntityTranslationDefaultHandler::entityFormSubmit()
EntityTranslationNodeHandler::entityFormSubmit in includes/translation.handler.node.inc
1 method overrides EntityTranslationDefaultHandler::entityFormSubmit()
EntityTranslationNodeHandler::entityFormSubmit in includes/translation.handler.node.inc

File

includes/translation.handler.inc, line 1586
Default translation handler for the translation module.

Class

EntityTranslationDefaultHandler
Class implementing the default entity translation behaviours.

Code

public function entityFormSubmit($form, &$form_state) {
  $form_langcode = $this
    ->getActiveLanguage();
  $translations = $this
    ->getTranslations();
  $is_translation = !empty($form_state['entity_translation']['is_translation']);
  $new_translation = !isset($translations->data[$form_langcode]);
  $values = isset($form_state['values']['translation']) ? $form_state['values']['translation'] : array();

  // Ensure every key has at least a default value. Subclasses may provide use
  // entity-specific values to alter them.
  $values += array(
    'status' => TRUE,
    'retranslate' => 0,
    'name' => isset($GLOBALS['user']->name) ? $GLOBALS['user']->name : '',
  );
  if (!isset($translations->data[$form_langcode])) {

    // If we have a new translation the language is the original entity
    // language.
    $translation = $is_translation ? array(
      'language' => $form_langcode,
      'source' => $this
        ->getSourceLanguage(),
    ) : array(
      'language' => $form_langcode,
      'source' => '',
    );
  }
  else {
    $translation = $translations->data[$form_langcode];
  }
  if (isset($values['translate'])) {
    $translation['translate'] = intval($values['translate']);
  }
  else {
    $this
      ->setOutdated($values['retranslate']);
  }

  // Handle possible language changes for the original values.
  if (!$is_translation) {
    $this
      ->setOriginalLanguage($form_langcode);
  }
  $translation['status'] = intval($values['status']);
  $translation['uid'] = $values['name'] ? user_load_by_name($values['name'])->uid : 0;
  $translation['created'] = empty($values['created']) ? REQUEST_TIME : strtotime($values['created']);
  $this
    ->setTranslation($translation);

  // If no redirect has been explicitly set, go to the edit form for the
  // current form language.
  if ($new_translation && empty($form_state['redirect']) && !$this
    ->isNewEntity()) {
    $form_state['redirect'] = $this
      ->getEditPath($form_langcode);
  }
}