You are here

function themekey_validator_node_type in ThemeKey 7.2

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

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

  • valid regular expression if operator is "~"
  • an existing content type if operator is "=" or "!"
  • must contain only lowercase letters, numbers, and underscores 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.

1 string reference to 'themekey_validator_node_type'
themekey_node_themekey_properties in modules/themekey.node.inc
Implements hook_themekey_properties().

File

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

Code

function themekey_validator_node_type($rule) {
  $errors = array();
  switch ($rule['operator']) {
    case '=':
    case '!':
      $node_types = node_type_get_types();
      if (!array_key_exists($rule['value'], $node_types)) {
        $errors['value'] = t('Possible values are %node_types', array(
          '%node_types' => '"' . implode('", "', array_keys($node_types)) . '"',
        ));
      }
      break;
    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 underscores");
      }
  }
  return $errors;
}