You are here

function themekey_validator_http_host in ThemeKey 7.3

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

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

  • valid regular expression if operator is "~"
  • must contain only lowercase letters, numbers, and hyphens 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.

2 string references to 'themekey_validator_http_host'
themekey_system_themekey_properties in modules/themekey.system.inc
Implements hook_themekey_properties().
themekey_user_themekey_properties in modules/themekey.user.inc
Implements hook_themekey_properties().

File

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

Code

function themekey_validator_http_host($rule) {
  $errors = array();
  switch ($rule['operator']) {
    case '~':
    case '!~':
      $errors = themekey_validator_regex($rule);
      break;
    default:
      if (!preg_match("/^[0-9a-z\\-.]+\$/", $rule['value'])) {
        $errors['value'] = t("Value isn't suitable. It can only contain lowercase letters, numbers, and hyphens");
      }
  }
  return $errors;
}