You are here

function themekey_example_validator_number_one in ThemeKey 7.3

Same name and namespace in other branches
  1. 7 themekey_example/themekey_example_validators.inc \themekey_example_validator_number_one()
  2. 7.2 themekey_example/themekey_example_validators.inc \themekey_example_validator_number_one()

Validates a Theme Switching Rule. Allowed Operators: "=", "!", "<", "<=", ">", ">=" Allowed values: string of digits (numbers)

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_example_validator_number_one'
hook_themekey_properties in docs/themekey.api.php
By Implementing hook_themekey_properties() it's possible to add new properties to ThemeKey.
themekey_example_themekey_properties in themekey_example/themekey_example.module
Implements hook_themekey_properties().

File

themekey_example/themekey_example_validators.inc, line 35
Validating functions of ThemeKey Example.

Code

function themekey_example_validator_number_one($rule) {
  $errors = array();
  switch ($rule['operator']) {
    case '~':
      $errors['operator'] = t('Possible operators are "=", "!", "<", "<=", ">" and ">="');
      break;
    case '=':
      if ('1' !== $rule['value']) {
        $errors['value'] = t('No other value than "1" makes sense for this operator');
      }
      break;
    default:
      if (!ctype_digit($rule['value'])) {
        $errors['value'] = t('Value must be a number');
      }
      break;
  }
  return $errors;
}