You are here

function themekey_validator_drupal_path in ThemeKey 7.3

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

Validates a Theme Switching Rule. Allowed Operators: "=", "!" Allowed values: paths without whitespace

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.

1 string reference to 'themekey_validator_drupal_path'
themekey_system_themekey_properties in modules/themekey.system.inc
Implements hook_themekey_properties().

File

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

Code

function themekey_validator_drupal_path($rule) {
  $errors = themekey_validator_no_whitespace($rule);
  switch ($rule['operator']) {
    case '=':
    case '!':
      if (strpos($rule['value'], '/') === 0) {
        $errors['value'] = t('A Drupal path must not start with "/"');
      }
      if (preg_match("@[^/][%#]@", $rule['value'])) {
        $errors['value'] = t('A wildcard can only be used to replace part(s) of the path, but not for parts of a word');
      }
      if (strpos($rule['value'], '?') !== FALSE) {
        $errors['value'] = t('Query strings will be stripped before a Drupal path is processed. Maybe you want to chain drupal:path and system:query_string or system:query_param (both provided by additional module ThemeKey Properties).');
      }
      break;
    default:
      $errors['operator'] = t('Possible operators are "=" and "!"');
  }
  return $errors;
}