You are here

function entity_translation_admin_form in Entity Translation 7

Builder function for the entity translation settings form.

1 string reference to 'entity_translation_admin_form'
entity_translation_menu in ./entity_translation.module
Implements hook_menu().

File

./entity_translation.admin.inc, line 11
The entity translation user interface.

Code

function entity_translation_admin_form($form, $form_state) {
  $options = array();
  $form['locale_field_language_fallback'] = array(
    '#type' => 'checkbox',
    '#title' => t('Allow language fallback'),
    '#description' => t('When language fallback is allowed, an alternative translation will be displayed if the requested language is not available. Other modules, such as <a href="https://www.drupal.org/project/language_hierarchy" target="_blank">Language Hierarchy</a>, are needed to manage which languages are used as fallbacks. Otherwise, existing translations will be chosen based on their <a href="!url">language weight</a>.', array(
      '!url' => url('admin/config/regional/language'),
    )),
    '#default_value' => variable_get('locale_field_language_fallback', TRUE),
  );
  $form['entity_translation_languages_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use only enabled languages'),
    '#description' => t('If checked, disabled languages will not show up as available languages. This setting does not apply to content types that are configured to use the Multilingual content (i18n_node) module as this module provides its own configuration.'),
    '#default_value' => variable_get('entity_translation_languages_enabled', FALSE),
  );
  $form['entity_translation_show_fallback_on_overview_pages'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show fallback statuses on overview pages'),
    '#description' => t('Enable to the show fallback information on the entity overview pages.'),
    '#default_value' => variable_get('entity_translation_show_fallback_on_overview_pages', FALSE),
    '#states' => array(
      'visible' => array(
        ':input[name="locale_field_language_fallback"]' => array(
          'checked' => TRUE,
        ),
      ),
    ),
  );
  $form['entity_translation_shared_labels'] = array(
    '#type' => 'checkbox',
    '#title' => t('Display shared labels'),
    '#description' => t('Append an "all languages" hint to entity form widgets shared across translations.'),
    '#default_value' => variable_get('entity_translation_shared_labels', TRUE),
  );
  $form['entity_translation_workflow_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable translation workflow permissions'),
    '#description' => t('By enabling the translation workflow permissions it will be possible to limit the access to the entity form elements. Once this is active every role previously allowed to access the entity form will need to be granted the <em>Edit original values</em> permission to edit the entity in the original language. Moreover, form elements dealing with values shared across the translations will be visible only to roles having been granted the <em>Edit shared values</em> permission.'),
    '#default_value' => entity_translation_workflow_enabled(),
  );
  $_null = NULL;
  list($items, ) = menu_router_build();
  _entity_translation_validate_path_schemes($_null, FALSE, $items);
  foreach (entity_get_info() as $entity_type => $info) {
    if ($info['fieldable']) {
      $et_info =& $info['translation']['entity_translation'];
      _entity_translation_process_path_schemes($entity_type, $et_info);
      _entity_translation_validate_path_schemes($et_info['path schemes'], $info['label']);

      // Translation can be enabled for the current entity only if it defines at
      // least one valid base path.
      foreach ($et_info['path schemes'] as $delta => $scheme) {
        if (!empty($scheme['base path'])) {
          $options[$entity_type] = !empty($info['label']) ? t($info['label']) : $entity_type;
          break;
        }
      }
    }
  }

  // Avoid bloating memory with unused data.
  drupal_static_reset('_entity_translation_validate_path_schemes');
  $enabled_types = array_filter(variable_get('entity_translation_entity_types', array()));
  $form['enabled'] = array(
    '#type' => 'fieldset',
    '#title' => t('Translatable entity types'),
    '#description' => t('Select which entities can be translated.'),
    '#collapsible' => TRUE,
    '#collapsed' => !empty($enabled_types),
  );
  $form['enabled']['entity_translation_entity_types'] = array(
    '#type' => 'checkboxes',
    '#options' => $options,
    '#default_value' => $enabled_types,
  );
  $form['tabs'] = array(
    '#type' => 'vertical_tabs',
  );
  $languages = array(
    ENTITY_TRANSLATION_LANGUAGE_DEFAULT => t('Default language'),
    ENTITY_TRANSLATION_LANGUAGE_CURRENT => t('Current language'),
    ENTITY_TRANSLATION_LANGUAGE_AUTHOR => t('Author language'),
    LANGUAGE_NONE => t('Language neutral'),
  );
  foreach (entity_translation_languages($entity_type) as $langcode => $language) {
    $languages[$langcode] = t($language->name);
  }
  foreach ($enabled_types as $entity_type) {
    $label = $options[$entity_type];
    $entity_info = entity_get_info($entity_type);
    $bundles = !empty($entity_info['bundles']) ? $entity_info['bundles'] : array(
      $entity_type => array(
        'label' => $label,
      ),
    );
    $enabled_bundles = 0;
    foreach ($bundles as $bundle => $info) {
      if (entity_translation_enabled_bundle($entity_type, $bundle)) {
        $enabled_bundles++;
        $settings = entity_translation_settings($entity_type, $bundle);
        $settings_key = 'entity_translation_settings_' . $entity_type . '__' . $bundle;
        $form['settings'][$entity_type][$settings_key] = array(
          '#tree' => TRUE,
        );

        // If the entity defines no bundle we do not need the fieldset.
        if (count($bundles) > 1 || $bundle != $entity_type) {
          $form['settings'][$entity_type][$settings_key] += array(
            '#type' => 'fieldset',
            '#title' => $info['label'],
            '#collapsible' => TRUE,
            '#collapsed' => TRUE,
          );
        }
        $form['settings'][$entity_type][$settings_key]['default_language'] = array(
          '#type' => 'select',
          '#title' => t('Default language'),
          '#options' => $languages,
          '#default_value' => $settings['default_language'],
        );
        $form['settings'][$entity_type][$settings_key]['hide_language_selector'] = array(
          '#type' => 'checkbox',
          '#title' => t('Hide language selector'),
          '#default_value' => $settings['hide_language_selector'],
        );
        $form['settings'][$entity_type][$settings_key]['exclude_language_none'] = array(
          '#type' => 'checkbox',
          '#title' => t('Exclude <em>Language neutral</em> from the available languages'),
          '#default_value' => $settings['exclude_language_none'],
        );
        $form['settings'][$entity_type][$settings_key]['lock_language'] = array(
          '#type' => 'checkbox',
          '#title' => t('Prevent language from being changed once the entity has been created'),
          '#default_value' => $settings['lock_language'],
        );
        $form['settings'][$entity_type][$settings_key]['shared_fields_original_only'] = array(
          '#type' => 'checkbox',
          '#title' => t('Hide shared elements on translation forms'),
          '#description' => t('Display form elements shared across translations only on entity forms for the original language.'),
          '#default_value' => $settings['shared_fields_original_only'],
        );
      }
    }
    if ($enabled_bundles > 0) {
      $form['settings'][$entity_type][$settings_key]['#collapsed'] = $enabled_bundles > 1;
      $form['settings'][$entity_type] += array(
        '#type' => 'fieldset',
        '#group' => 'tabs',
        '#title' => $label,
      );
    }
  }
  if (module_exists('pathauto')) {
    $form['pathauto'] = array(
      '#type' => 'fieldset',
      '#title' => t('Pathauto'),
      '#collapsible' => FALSE,
    );
    $form['pathauto']['entity_translation_pathauto_state_active_new_translation'] = array(
      '#title' => t('Pathauto state automatically activated on forms for new translations'),
      '#type' => 'checkbox',
      '#description' => t('When this option is enabled, the Pathauto state checkbox is automatically selected on the add-translation form. <br/><b>Attention:</b>When combining this option with the next one it may lead to cases where all aliases for all languages are auto-updated whenever a new translation is added.'),
      '#default_value' => variable_get('entity_translation_pathauto_state_active_new_translation', TRUE),
    );

    // These are the possible options when pathauto state is active.
    $mode_options = array(
      'generate_alias_active_language' => t('Generate alias only for current language'),
      'generate_missing_aliases_all_languages' => t('Generate missing aliases for all languages'),
      'generate_all_aliases_all_languages' => t('Generate all aliases for all languages'),
    );

    // Single entity update mode.
    $form['pathauto']['entity_translation_pathauto_state_mode_update'] = array(
      '#title' => t('Pathauto state mode for single update'),
      '#type' => 'select',
      '#description' => t('When the Pathauto state is activated, the mode defined here will be used for alias generation, on a single update, e.g. when editing a node using the node edit form.'),
      '#options' => $mode_options,
      '#default_value' => variable_get('entity_translation_pathauto_state_mode_update', 'generate_alias_active_language'),
    );

    // Bulk entity updates mode.
    $form['pathauto']['entity_translation_pathauto_state_mode_bulkupdate'] = array(
      '#title' => t('Pathauto state mode for bulk updates'),
      '#type' => 'select',
      '#description' => t('When the Pathauto state is activated, the mode defined here will be used for alias generation, on bulk updates.'),
      '#options' => $mode_options,
      '#default_value' => variable_get('entity_translation_pathauto_state_mode_bulkupdate', 'generate_all_aliases_all_languages'),
    );
  }
  $form = system_settings_form($form);

  // Menu rebuilding needs to be performed after the system settings are saved.
  $form['#submit'][] = 'entity_translation_admin_form_submit';
  return $form;
}