You are here

function lingotek_admin_profiles_form in Lingotek Translation 7.6

Same name and namespace in other branches
  1. 7.7 lingotek.admin.inc \lingotek_admin_profiles_form()
  2. 7.4 lingotek.admin.inc \lingotek_admin_profiles_form()
  3. 7.5 lingotek.admin.inc \lingotek_admin_profiles_form()
1 string reference to 'lingotek_admin_profiles_form'
lingotek_admin_configuration_view in ./lingotek.admin.inc

File

./lingotek.admin.inc, line 1547

Code

function lingotek_admin_profiles_form($form, &$form_state, $show_fieldset = FALSE) {
  $profiles = lingotek_get_profiles_by_name(TRUE);

  // these will already be translated using the t-function
  $form['header'] = array(
    '#type' => 'item',
    '#title' => t('Translation Profiles'),
    '#description' => t('Translation management defaults used when creating new entities. At the entity level, these settings can be adjusted.'),
  );
  $headers = array(
    t('Profile Name'),
    t('Usage'),
    t('Actions'),
  );
  $total_count_with_profiles = 0;
  $rows = array();
  $profiles_excluded_from_editing = array(
    'CUSTOM',
    'DISABLED',
  );
  $profiles_excluded_from_showing = array(
    LingotekSync::PROFILE_CONFIG,
  );
  foreach ($profiles as $key => $profile_name) {
    if (in_array((string) $key, $profiles_excluded_from_showing)) {
      continue;
    }
    elseif (in_array((string) $key, $profiles_excluded_from_editing)) {
      $edit_link = '<i class="fa fa-gear fa-lg ltk-disabled-icon"></i>';
    }
    else {
      $edit_link = '<a href="' . url(LINGOTEK_MENU_MAIN_BASE_URL . '/settings/profile/' . $key) . '" class="ctools-use-modal ctools-modal-lingotek-style" title="' . t('Edit') . '"><i class="fa fa-gear fa-lg"></i></a>';
    }

    // styling for modals
    drupal_add_js(array(
      'lingotek-style' => array(
        'closeImage' => theme('image', array(
          'path' => drupal_get_path('module', 'lingotek') . '/images/close.png',
          'alt' => t('Close window'),
          'title' => t('Close window'),
        )),
        'closeText' => '',
        'animation' => 'fadeIn',
      ),
    ), 'setting');
    $count_by_entity_type = lingotek_admin_profile_usage($key);
    $count_types = lingotek_admin_profile_usage_by_types($key);
    $total_count_with_profiles += array_sum($count_by_entity_type);
    $entities_str = '';
    $total_entities = 0;
    foreach ($count_by_entity_type as $entity_type => $count) {
      if (!empty($entities_str)) {
        $entities_str .= ', ';
      }
      $entities_str .= $count . ' ' . format_plural($count, $entity_type, $entity_type . 's');
      $total_entities += $count;
    }
    $entities_str = strlen(trim($entities_str)) ? " ({$entities_str})" : "";
    $entities_str = $total_entities . ' ' . format_plural($total_entities, "entity", "entities") . $entities_str;

    // The custom profile line should not be shown unless there are entities assigned as 'custom'
    if ($key !== 'CUSTOM') {
      $rows[] = array(
        $profile_name,
        $entities_str . ', ' . $count_types . ' ' . format_plural($count_types, 'content type', 'content types'),
        $edit_link,
      );
    }
    elseif ($count_by_entity_type) {
      $rows[] = array(
        $profile_name,
        $entities_str,
        $edit_link,
      );
    }
  }
  $variables = array(
    'header' => $headers,
    'rows' => $rows,
    'attributes' => array(
      'id' => 'lingotek-profiles',
    ),
  );
  $form['profiles'] = array(
    '#markup' => theme('table', $variables),
  );
  $form['add'] = array(
    '#markup' => t('<p><a href="@url" class="ctools-use-modal ctools-modal-lingotek-style"><i class="fa fa-plus" style="padding-right:3px"></i>Add new profile</a></p>', array(
      '@url' => url(LINGOTEK_MENU_MAIN_BASE_URL . '/settings/profile/add'),
    )),
  );
  $form['#action'] = url('admin/settings/lingotek/settings', array(
    'fragment' => 'ltk-profiles',
  ));
  return $form;
}