You are here

function entity_translation_form_alter in Entity Translation 7

Implements hook_form_alter().

File

./entity_translation.module, line 1504

Code

function entity_translation_form_alter(&$form, &$form_state) {
  if ($info = entity_translation_edit_form_info($form, $form_state)) {
    $handler = entity_translation_get_handler($info['entity type'], $info['entity']);
    if (entity_translation_enabled($info['entity type'], $info['entity'])) {
      if (!$handler
        ->isNewEntity()) {
        $handler
          ->entityForm($form, $form_state);
        $translations = $handler
          ->getTranslations();
        $form_langcode = $handler
          ->getActiveLanguage();
        if (!isset($translations->data[$form_langcode]) || count($translations->data) > 1) {

          // Hide shared form elements if the user is not allowed to edit them.
          $handler
            ->entityFormSharedElements($form);
        }
      }
      else {
        $handler
          ->entityFormLanguageWidget($form, $form_state);
      }

      // We need to process the posted form as early as possible to update the
      // form language value.
      array_unshift($form['#validate'], 'entity_translation_entity_form_validate');
    }
    else {
      $handler
        ->entityFormLanguageWidget($form, $form_state);
    }
  }
}