function translation_entity_form_field_ui_field_edit_form_alter

Implements hook_form_FORM_ID_alter().

File

drupal/core/modules/translation_entity/translation_entity.module, line 577
Allows entities to be translated into different languages.

Code

function translation_entity_form_field_ui_field_edit_form_alter(array &$form, array &$form_state, $form_id) {
  $field = $form['#field'];
  $field_name = $field['field_name'];
  $translatable = $field['translatable'];
  $label = t('Field translation');
  $title = t('Users may translate this field.');
  $form['field']['#collapsed'] = $translatable;
  if (field_has_data($field)) {
    $path = "admin/config/regional/translation_entity/translatable/{$field_name}";
    $status = $translatable ? $title : t('This field has data in existing content.');
    $link_title = !$translatable ? t('Enable translation') : t('Disable translation');
    $form['field']['translatable'] = array(
      '#prefix' => '<div class="translatable"><label>' . $label . '</label>',
      '#suffix' => '</div>',
      'message' => array(
        '#markup' => $status . ' ',
      ),
      'link' => array(
        '#type' => 'link',
        '#title' => $link_title,
        '#href' => $path,
        '#options' => array(
          'query' => drupal_get_destination(),
        ),
        '#access' => user_access('toggle field translatability'),
      ),
    );
  }
  else {
    $form['field']['translatable'] = array(
      '#prefix' => '<label>' . $label . '</label>',
      '#type' => 'checkbox',
      '#title' => $title,
      '#default_value' => $translatable,
    );
  }
}