You are here

function themekey_property_value in ThemeKey 7.2

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

Detects if a ThemeKey property's value for the current page request.

Parameters

$parameters: reference to an array containing all ThemeKey properties and their values

$property: the name of the property as string

Return value

The value of the property:

  • string if it's a single value
  • array of strings if there're multiple values
  • NULL if no value
2 calls to themekey_property_value()
themekey_debug_properties in ./themekey_debug.module
Iterates over all ThemeKey Properties and prints out their current values.
themekey_match_condition in ./themekey_base.inc
Detects if a ThemeKey rule matches to the current page request.

File

./themekey_base.inc, line 473
The functions in this file are the back end of ThemeKey.

Code

function themekey_property_value(&$parameters, $property) {

  // TODO Warning if property is not part of variable_get('themekey_attributes')
  // Property value is available directly
  if (isset($parameters[$property])) {
    return $parameters[$property];
  }
  $parameters[$property] = NULL;
  $src_candidates = array();
  $maps = variable_get('themekey_maps', array());
  foreach ($maps as $pos => $map) {
    if ($map['dst'] == $property) {
      if (!empty($parameters[$map['src']])) {
        $map_func = $map['callback'];
        if (!function_exists($map_func) && isset($map['file'])) {
          themekey_load_function($map_func, $map['file'], isset($map['path']) ? $map['path'] : '');
        }
        $arguments = isset($map['args']) ? $map['args'] : array();
        if (function_exists($map_func)) {
          $parameters[$property] = $map_func($parameters[$map['src']], $arguments);
        }
        else {
          themekey_set_debug_message('Map function %map_function does not exists', array(
            '%map_function' => $map_func,
          ));
          watchdog('php', 'ThemeKey map function %map_function does not exists', array(
            '%map_function' => $map_func,
          ), WATCHDOG_ERROR);
        }
        break;
      }
      $src_candidates[$pos] = $map['src'];
    }
  }
  if (is_null($parameters[$property]) && !empty($src_candidates)) {
    foreach ($src_candidates as $pos => $src) {
      $return = themekey_property_value($parameters, $src);
      if ($return) {
        $map_func = $maps[$pos]['callback'];
        $parameters[$property] = $map_func($return, $parameters);
        break;
      }
    }
  }
  return $parameters[$property];
}