function _translation_entity_form_language_content_settings_form_alter

(proxied) Implements hook_form_FORM_ID_alter().

1 call to _translation_entity_form_language_content_settings_form_alter()

File

drupal/core/modules/translation_entity/translation_entity.admin.inc, line 60
The entity translation administration forms.

Code

function _translation_entity_form_language_content_settings_form_alter(array &$form, array &$form_state) {

  // Inject into the content language settings the translation settings if the
  // user has the required permission.
  if (!user_access('administer entity translation')) {
    return;
  }
  $default = $form['entity_types']['#default_value'];
  foreach ($default as $entity_type => $enabled) {
    $default[$entity_type] = $enabled || translation_entity_enabled($entity_type) ? $entity_type : FALSE;
  }
  $form['entity_types']['#default_value'] = $default;
  $form['#attached']['library'][] = array(
    'translation_entity',
    'drupal.translation_entity.admin',
  );
  $form['#attached']['js'][] = array(
    'data' => drupal_get_path('module', 'translation_entity') . '/translation_entity.admin.js',
    'type' => 'file',
  );
  $dependent_options_settings = array();
  foreach ($form['#labels'] as $entity_type => $label) {
    $entity_info = entity_get_info($entity_type);
    foreach (entity_get_bundles($entity_type) as $bundle => $bundle_info) {

      // Here we do not want the widget to be altered and hold also the "Enable
      // translation" checkbox, which would be redundant. Hence we add this key
      // to be able to skip alterations.
      $form['settings'][$entity_type][$bundle]['settings']['language']['#translation_entity_skip_alter'] = TRUE;

      // Only show the checkbox to enable translation if the bundles in the
      // entity might have fields and if there are fields to translate.
      if (!empty($entity_info['fieldable'])) {
        $fields = field_info_instances($entity_type, $bundle);
        if ($fields) {
          $form['settings'][$entity_type][$bundle]['translatable'] = array(
            '#type' => 'checkbox',
            '#default_value' => translation_entity_enabled($entity_type, $bundle),
          );

          // @todo Exploit field definitions once all core entities and field
          // types are migrated to the Entity Field API.
          foreach ($fields as $field_name => $instance) {
            $field = field_info_field($field_name);
            $form['settings'][$entity_type][$bundle]['fields'][$field_name] = array(
              '#label' => $instance['label'],
              '#type' => 'checkbox',
              '#default_value' => $field['translatable'],
            );
            $column_element = translation_entity_field_sync_widget($field, $instance);
            if ($column_element) {
              $form['settings'][$entity_type][$bundle]['columns'][$field_name] = $column_element;
              if (isset($column_element['#options']['file'])) {
                $dependent_options_settings["settings[{$entity_type}][{$bundle}][columns][{$field_name}]"] = array(
                  'file',
                );
              }
            }
          }
        }
      }
    }
  }
  $settings = array(
    'dependent_selectors' => $dependent_options_settings,
  );
  $form['#attached']['js'][] = array(
    'data' => array(
      'translationEntityDependentOptions' => $settings,
    ),
    'type' => 'setting',
  );
  $form['#validate'][] = 'translation_entity_form_language_content_settings_validate';
  $form['#submit'][] = 'translation_entity_form_language_content_settings_submit';
}