You are here

function i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument in Internationalization Views 7.3

Same name and namespace in other branches
  1. 6.3 includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc \i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument()
  2. 6.2 includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc \i18nviews_plugin_argument_validate_i18n_taxonomy_term::validate_argument()

Overrides views_plugin_argument_validate_taxonomy_term::validate_argument

File

includes/i18nviews_plugin_argument_validate_i18n_taxonomy_term.inc, line 50
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_argument($argument) {
  $vocabularies = $this->options['vocabularies'];
  $type = $this->options['type'];
  $transform = $this->options['transform'];
  switch ($type) {
    case 'i18n_tid':
    case 'i18n_tids':
    case 'i18n_name':
    case 'i18n_convert':

      // Check to see if the term is in fact localised
      $localised = i18nviews_locale_source($argument, 'taxonomy');
      if (!empty($localised)) {

        // If it is localised I set the $argument to the orginal and tell the view that the argument has been localized and to use the source
        $argument = $localised->source;
        $this->argument->argument = $localised->source;
      }
      if ($type == 'i18n_tid' || $type == 'i18n_tids') {
        return $this
          ->{"validate_argument_{$type}"}($argument, $vocabularies);
      }
      $query = db_select('taxonomy_term_data', 'td');
      $query
        ->leftJoin('taxonomy_vocabulary', 'tv', 'td.vid = tv.vid');
      $query
        ->fields('td');
      $query
        ->fields('tv', array(
        'machine_name',
      ));
      if (!empty($vocabularies)) {
        $query
          ->condition('tv.machine_name', $vocabularies);
      }
      if ($transform) {
        $query
          ->where("replace(td.name, ' ', '-') = :name", array(
          ':name' => $argument,
        ));
      }
      else {
        $query
          ->condition('td.name', $argument);
      }
      $term = $query
        ->execute()
        ->fetchObject();
      if ($term && (empty($vocabularies) || !empty($vocabularies[$term->machine_name]))) {
        if ($type == 'i18n_convert') {
          $this->argument->argument = $term->tid;
        }

        // ToDo: check vocabulary translation mode (if localization needed)
        $this->argument->validated_title = check_plain(i18n_taxonomy_term_name($term));
        return TRUE;
      }
      return FALSE;
  }
}