You are here

function i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_form in Internationalization Views 6.2

File

includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc, line 12
Contains the 'Taxonomy term (i18n)' argument validator plugin.

Class

i18nviews_plugin_argument_validate_i18n_taxonomy_term
Validate whether an argument is a localized term.

Code

function validate_form(&$form, &$form_state) {
  $vocabularies = taxonomy_get_vocabularies();
  $options = array();

  // Get the localized vocabularies.
  $localisedvocabs = variable_get('i18ntaxonomy_vocabulary', array());

  // Only add the localized vocabularies as options.
  foreach ($localisedvocabs as $localisedvocab => $localisedtype) {
    if ($localisedtype == '1') {
      $options[$localisedvocab] = check_plain($vocabularies[$localisedvocab]->name);
    }
  }
  $form['validate_argument_vocabulary_i18n'] = array(
    '#type' => 'checkboxes',
    '#prefix' => '<div id="edit-options-validate-argument-vocabulary-i18n-wrapper">',
    '#suffix' => '</div>',
    '#title' => t('Vocabularies'),
    '#options' => $options,
    '#default_value' => isset($this->argument->options['validate_argument_vocabulary_i18n']) ? $this->argument->options['validate_argument_vocabulary_i18n'] : array(),
    '#description' => t('Limit this validator to vocabularies that have been localized'),
    '#process' => array(
      'expand_checkboxes',
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );
  $form['validate_argument_type_i18n'] = array(
    '#type' => 'select',
    '#title' => t('Argument type'),
    '#options' => array(
      'i18n_name' => t('Localised Term name or synonym'),
      'i18n_convert' => t('Localised Term name/synonym converted to Term ID'),
    ),
    '#default_value' => isset($this->argument->options['validate_argument_type_i18n']) ? $this->argument->options['validate_argument_type_i18n'] : 'i18n_name',
    '#description' => t('Select the form of this argument; if using term name, it is generally more efficient to convert it to a term ID and use Taxonomy: Term ID rather than Taxonomy: Term Name" as an argument.'),
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-type' => array(
        $this->id,
      ),
    ),
  );
  $form['validate_argument_transform_i18n'] = array(
    '#type' => 'checkbox',
    '#title' => t('Transform dashes in URL to spaces in term name arguments'),
    '#default_value' => isset($this->argument->options['validate_argument_transform_i18n']) ? $this->argument->options['validate_argument_transform_i18n'] : FALSE,
    '#process' => array(
      'views_process_dependency',
    ),
    '#dependency' => array(
      'edit-options-validate-argument-type' => array(
        'convert',
      ),
    ),
  );
}