You are here

function themekey_validator_language in ThemeKey 7.2

Same name and namespace in other branches
  1. 6.4 themekey_validators.inc \themekey_validator_language()
  2. 6.2 themekey_validators.inc \themekey_validator_language()
  3. 6.3 themekey_validators.inc \themekey_validator_language()
  4. 7.3 themekey_validators.inc \themekey_validator_language()
  5. 7 themekey_validators.inc \themekey_validator_language()

Validates a Theme Switching Rule. Allowed Operators: any Allowed values:

  • configured Drupal language as string or 'und' if operator is "="
  • valid regular expression if operator is "~"
  • any string for different operators

Parameters

$rule: A Theme Switching Rule as associative array:

  • property: ThemeKey property as string (e.g., "drupal:path")
  • wildcard: optional string, only used if property is "drupal:path:wildcard"
  • operator: ThemeKey operator as string ("=", "!", "*", "!*", "<", "<=", ">", ">=", "~", "!~")
  • value: ThemeKey property value as string

Return value

An associative array of errors:

  • property: translated error message as string describing a problem with the property
  • wildcard: translated error message as string describing a problem with the wildcard
  • operator: translated error message as string describing a problem with the operator
  • value: translated error message as string describing a problem with the value

If no errors detected the array is empty.

3 string references to 'themekey_validator_language'
themekey_locale_themekey_properties in modules/themekey.locale.inc
Implements hook_themekey_properties().
themekey_node_themekey_properties in modules/themekey.node.inc
Implements hook_themekey_properties().
themekey_user_themekey_properties in modules/themekey.user.inc
Implements hook_themekey_properties().

File

./themekey_validators.inc, line 174
Provides set of validators which can be used to validate ThemeKey Theme Switching Rules.

Code

function themekey_validator_language($rule) {
  $errors = array();
  switch ($rule['operator']) {
    case '=':
    case '!':
      $languages = language_list();

      // add 'neutral' to the list of languages
      $languages['neutral'] = TRUE;
      if (!array_key_exists($rule['value'], $languages)) {
        $errors['value'] = t('Possible values are %languages', array(
          '%languages' => '"' . implode('", "', array_keys($languages)) . '"',
        ));
      }
      break;
    case '~':
    case '!~':
      $errors = themekey_validator_regex($rule);
      break;
  }
  return $errors;
}