You are here

function languagefield_field_settings_form in Custom Language field 7

Implements hook_field_settings_form().

File

./languagefield.module, line 60
Provides a list of languages from ISO 639 standard. All variables of a $language-object can be found here: http://api.drupal.org/api/drupal/developer--globals.php/global/language

Code

function languagefield_field_settings_form($field, $instance, $has_data) {
  $settings = $field['settings'];

  // oct 2014: choice of languages from radio to checkbox.
  if (!is_array($settings['enabled'])) {
    $settings['enabled'] = array(
      $settings['enabled'] => $settings['enabled'],
    );
  }
  $options_list = languagefield_options_list($field, NULL, NULL, NULL);
  $form['enabled'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Enabled Languages'),
    '#default_value' => $settings['enabled'],
    '#required' => TRUE,
    '#options' => array(
      LANGUAGEFIELD_LANGUAGES_ALL => t('All Predefined languages'),
      LANGUAGEFIELD_LANGUAGES_INSTALLED => t('All installed languages'),
      LANGUAGEFIELD_LANGUAGES_ENABLED => t('Enabled installed languages'),
      // The following are copied from LanguageConfiguration::getDefaultOptions()
      LANGUAGEFIELD_SITE_DEFAULT => t("Site's default language (!language)", array(
        '!language' => language_default()->name,
      )) . '*',
      LANGUAGEFIELD_CURRENT_INTERFACE => t('Current interface language') . '*',
      LANGUAGEFIELD_AUTHORS_DEFAULT => t("Author's preferred language") . '*',
      LANGUAGE_NONE => t("Language neutral ('und')"),
    ),
    '#description' => t("Installed languages can be maintained on the\n      <a href='@languages-page'>@languages</a>\n      page, when Locale module is enabled. Options marked with '*' are\n      typically used as default value in a hidden widget.", array(
      '@languages' => t('Languages'),
      '@languages-page' => url('admin/config/regional/language'),
    )),
  );

  // oct 2012: new options for display in widget.
  $form['format'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Display in widget'),
    '#description' => t('Select the elements you want to show. The elements will be concatenated when showing the field.'),
    '#default_value' => $settings['format'],
    '#options' => _languagefield_settings_options('widget'),
    '#required' => TRUE,
  );

  // oct 2012: old options for display in widget: move old data and hide old options (not removed, until proper upgrade path.).
  if (!empty($settings['include_native'])) {
    $form['format']['#default_value']['name_native'] = 'name_native';
    unset($settings['include_native']);
    $settings['include_native'] = '0';
    $form['include_native'] = array(
      '#type' => 'hidden',
      //      '#type' => 'checkbox',
      //      '#title' => t('Show native language name in widget (E.g., German vs. German (Deutsch))'),
      '#default_value' => !empty($settings['include_native']),
    );
  }
  $form['languages'] = array(
    '#type' => 'select',
    '#title' => t('Restrict by language'),
    '#default_value' => $settings['languages'],
    '#options' => array(
      '' => t('--'),
    ) + $options_list,
    '#description' => t('If no languages are selected, this filter will not be used.'),
    '#multiple' => TRUE,
    '#size' => 10,
  );
  $form['excluded_languages'] = array(
    '#type' => 'select',
    '#title' => t('Excluded languages'),
    '#default_value' => $settings['excluded_languages'],
    '#options' => array(
      '' => t('--'),
    ) + $options_list,
    '#description' => t('This removes individual languages from the list.'),
    '#multiple' => TRUE,
    '#size' => 10,
  );
  $form['groups'] = array(
    '#type' => 'textarea',
    '#title' => t('Language groups'),
    '#default_value' => $settings['groups'],
    '#description' => t("Provides a simple way to group common languages. If no groups are provided, no groupings will be used. Enter in the following format:<br/><code>cn,en,ep,ru<br/>African languages|bs,br<br/>Asian languages|cn,km,fil,ja</code>"),
    '#multiple' => TRUE,
    '#size' => 10,
  );
  $form['groups_help'] = array(
    '#type' => 'fieldset',
    '#title' => t('Group help'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $items = array();
  foreach (_languagefield_options() as $language) {
    $items[] = t('<strong>!key</strong>: %title', array(
      '!key' => $language['langcode'],
      '%title' => $language['name'],
    ));
  }
  $form['groups_help']['keys'] = array(
    '#type' => 'item',
    '#title' => t('Full language / key listing'),
    '#markup' => theme('item_list', array(
      'items' => $items,
    )),
  );
  $form['groups_help']['all'] = array(
    '#type' => 'item',
    '#title' => t('Available keys'),
    '#markup' => '<p>' . implode(',', array_keys(_languagefield_options())) . '</p>',
  );
  return $form;
}