You are here

public function EntityTranslationDefaultHandler::entityFormValidate in Entity Translation 7

Overrides EntityTranslationHandlerInterface::entityFormValidate

See also

EntityTranslationHandlerInterface::entityFormValidate()

File

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

Class

EntityTranslationDefaultHandler
Class implementing the default entity translation behaviours.

Code

public function entityFormValidate($form, &$form_state) {

  // The locale module is creating the node object anew based on the form's
  // submitted values, thus losing the relation with the currently assigned
  // translation handler. By adding the 'entity_translation_handler_id' property to
  // the $form_state['values'] array, we can persist that relation and utilize
  // a correctly instantiated translation handler for the new node entity.
  if (empty($form_state['values']['entity_translation_handler_id']) && field_has_translation_handler($this
    ->getEntityType(), 'locale')) {
    $form_state['values']['entity_translation_handler_id'] = $form_state[$this
      ->getEntityType()]->entity_translation_handler_id;
  }
  if (!empty($form_state['values']['translation'])) {
    $values = $form_state['values']['translation'];

    // Validate the "authored by" field.
    if (!empty($values['name']) && !($account = user_load_by_name($values['name']))) {
      form_set_error('translation][name', t('The translation authoring username %name does not exist.', array(
        '%name' => $values['name'],
      )));
    }

    // Validate the "authored on" field.
    if (!empty($values['created']) && strtotime($values['created']) === FALSE) {
      form_set_error('translation][created', t('You have to specify a valid translation authoring date.'));
    }
  }
}