You are here

function lingotek_admin_entity_bundle_profiles_form in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.admin.inc \lingotek_admin_entity_bundle_profiles_form()
  2. 7.6 lingotek.admin.inc \lingotek_admin_entity_bundle_profiles_form()

Content translation form

2 calls to lingotek_admin_entity_bundle_profiles_form()
lingotek_setup_comment_translation_settings_form in ./lingotek.setup.inc
lingotek_setup_node_translation_settings_form in ./lingotek.setup.inc
Entity Translation Settings - Form Layout Select the Content Types and Fields to be Translated.
1 string reference to 'lingotek_admin_entity_bundle_profiles_form'
lingotek_admin_configuration_view in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 135

Code

function lingotek_admin_entity_bundle_profiles_form($form, &$form_state, $entity_type, $show_fieldset = FALSE) {
  drupal_add_js('misc/collapse.js');
  $setup_complete = !lingotek_is_config_missing();
  $entity_type_info = entity_get_info($entity_type);
  $bundles = $entity_type_info['bundles'];

  // sort alphabetically by label
  uasort($bundles, 'lingotek_label_compare');

  // Add the default bundle related to message types, if applicable.
  if ($entity_type == 'message_type' && module_exists('message')) {
    $bundles['message_type'] = array(
      'label' => 'message_type',
      'rdf_mapping' => array(),
    );
  }
  $profiles_options = lingotek_get_profiles_by_name();

  // these will come translated via the t-function
  if (isset($profiles_options[LingotekSync::PROFILE_CONFIG])) {
    unset($profiles_options[LingotekSync::PROFILE_CONFIG]);
  }
  if ($entity_type == 'field_collection_item') {
    $profiles_options = array(
      'ENABLED' => t('Enabled'),
      LingotekSync::PROFILE_DISABLED => t('Disabled'),
    );
    $entity_type_info['label'] = 'Field Collection';
  }
  drupal_alter('lingotek_entity_profiles_options', $entity_type, $profiles_options);
  $entity_profiles = variable_get('lingotek_entity_profiles');
  $form['entity_type'] = array(
    '#type' => 'hidden',
    '#value' => $entity_type,
  );
  $selector = '.lingotek-content-settings-table.' . $entity_type;
  $title_str = $setup_complete ? t('Translate @types', array(
    '@type' => $entity_type_info['label'],
  )) : t('Which content types do you want translated?');
  $form['translation_' . $entity_type] = array(
    '#type' => $show_fieldset ? 'fieldset' : 'item',
    '#title' => check_plain($title_str),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#group' => 'administrative_settings',
    'actions' => array(
      '#type' => 'actions',
    ),
    '#submit' => array(
      'lingotek_admin_entity_bundle_profiles_form_submit',
    ),
  );
  $change_all_select = 'Set all to: <select id="change-all-profiles" name="all_profile_' . $entity_type . '" onchange="lingotek_set_all(\'' . $selector . '\', this)">';
  $change_all_select .= '<option selected disabled hidden>Select Option...</option>';
  foreach ($profiles_options as $key => $profile_option) {
    $change_all_select .= '<option value="' . $key . '">' . $profile_option . '</option>';
  }
  $change_all_select .= '<select>';
  $form['translation_' . $entity_type][] = array(
    '#type' => 'item',
    '#markup' => $change_all_select,
  );
  $translatable_field_types = lingotek_get_translatable_field_types();
  $enabled_fields = variable_get('lingotek_enabled_fields', array());
  $translate = isset($enabled_fields[$entity_type]) ? $enabled_fields[$entity_type] : array();
  $rows = array();
  foreach ($bundles as $bundle_name => $bundle) {
    $original_fields = field_info_instances($entity_type, $bundle_name);
    $fields = lingotek_node_settings_row_fields($entity_type, $bundle_name, $setup_complete, $translatable_field_types, $translate);
    $translation_mode = $entity_type == 'taxonomy_term' ? lingotek_get_translation_mode($bundle_name) : NULL;
    $config_handled = $entity_type == 'taxonomy_term' && empty($original_fields) && $translation_mode['#markup'] !== 'Translate';
    $translation_handling = $config_handled ? array(
      '#markup' => 'Config',
    ) : array(
      '#markup' => 'Bundle',
    );
    $profiles = lingotek_node_settings_row_profiles($bundle_name, $entity_profiles, $entity_type, $profiles_options, $setup_complete, $config_handled);
    $entity_specifics = array(
      'translation_mode' => $translation_mode,
      'translation_handling' => $translation_handling,
    );
    if ($config_handled) {
      $fields = array(
        'config' => array(
          '#markup' => t('These fields are translated from the config tab'),
        ),
      );
    }
    $languages = lingotek_get_target_locales(FALSE);
    $bundle['collapsible_label'] = lingotek_get_language_specific_labels($entity_type, $bundle, $languages);
    if ($translation_mode['#markup'] == 'Fixed' || $translation_mode['#markup'] == 'No') {
      continue;
    }
    $rows[$bundle_name] = lingotek_node_settings_row($entity_type, $bundle, $profiles, $fields, $entity_specifics);
  }
  $header = array(
    t('Content Type'),
    t('Translation Profile&nbsp;*'),
    t('Fields'),
  );
  if ($entity_type == 'node') {
    $header = array(
      t('Content Type'),
      t('Translation Profile&nbsp;*'),
      t('Fields'),
    );
  }
  elseif ($entity_type == 'taxonomy_term') {
    $header = array(
      t('Content Type'),
      t('Translation Profile&nbsp;*'),
      t('Translation Mode'),
      t('Translation Handling'),
      t('Fields'),
    );
  }
  elseif ($entity_type == 'field_collection_item') {
    $header = array(
      t('Collection Name'),
      t('Status&nbsp;*'),
      t('Fields'),
    );
  }
  $variables = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'lingotek-content-settings-table',
        $entity_type,
      ),
    ),
  );
  $form['translation_' . $entity_type]['types'] = array(
    '#type' => 'markup',
    '#markup' => theme('table', $variables),
  );
  if ($setup_complete) {
    $node_message = '';
    if (variable_get('lingotek_translate_original_node_titles', FALSE) && $entity_type === 'node') {
      $node_message = "<br />Note: If \"Node Title\" and \"Title\" are both translated, \"Title\" will display within nodes.";
    }
    $form['translation_' . $entity_type]['types']['#suffix'] = t('Note: Changing the default profile will affect only future content.  Existing content will keep current profile settings.  (To switch the profile for existing content, use the \'Edit translation settings\' action on the Manage tab.)' . $node_message, array(
      '@entity_type' => strtolower($entity_type_info['label']),
    ));
    $form['#action'] = url('admin/settings/lingotek/settings', array(
      'fragment' => lingotek_get_tab_id($entity_type),
    ));
  }
  lingotek_admin_add_entity_specific_changes($form, $form_state, $entity_type);
  $form['translation_' . $entity_type]['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}