You are here

function themekey_match_rule_childs in ThemeKey 7.2

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

Helper function of

Parameters

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

$parent: id of parent rule

Return value

NULL in case of an error string name of the theme if child rule matched FALSE if no child rule matches TRUE if no child properties in the chain

See also

themekey_match_rules()

1 call to themekey_match_rule_childs()
themekey_match_rules in ./themekey_base.inc
This function steps through the rule chain and returns a theme.

File

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

Code

function themekey_match_rule_childs(&$parameters, $parent = 0) {
  static $child_lookups = array();
  if (isset($child_lookups[$parent])) {

    // prevent endless recursion in case of malformatted data in database
    return $child_lookups[$parent];
  }
  if ($result = db_select('themekey_properties', 'tp')
    ->fields('tp')
    ->condition('enabled', 1)
    ->condition('parent', $parent)
    ->condition('value', '', '<>')
    ->orderBy('weight', 'asc')
    ->execute()) {
    $num_childs = 0;
    foreach ($result as $item) {
      $num_childs++;
      if (themekey_match_condition($item, $parameters)) {
        if ('drupal:path' == $item->property && !empty($parameters['internal:temp_wildcards'])) {
          $wildcards = unserialize($item->wildcards);
          if (!empty($wildcards)) {
            foreach ($wildcards as $index => $wildcard) {
              $parameters[$wildcard] = $parameters['internal:temp_wildcards'][$index];
            }
          }
        }
        if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
          themekey_set_debug_message('Match: %rule', array(
            '%rule' => themekey_format_rule_as_string($item->id),
          ));
        }
        $child_lookups[$parent] = themekey_match_rule_childs($parameters, $item->id);
        if (FALSE === $child_lookups[$parent]) {
          continue;
        }
        elseif (TRUE === $child_lookups[$parent]) {
          if (!themekey_check_theme_enabled($item->theme)) {
            if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
              themekey_set_debug_message('Theme disabled: %theme', array(
                '%theme' => $item->theme,
              ));
            }
            continue;
          }
          $child_lookups[$parent] = $item->theme;
        }

        // return own theme or theme from child property or NULL in case of a database error
        return $child_lookups[$parent];
      }
      elseif (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
        themekey_set_debug_message('No match: %rule', array(
          '%rule' => themekey_format_rule_as_string($item->id),
        ));
      }
    }
    $child_lookups[$parent] = !$num_childs;
    return $child_lookups[$parent];
  }
  $child_lookups[$parent] = NULL;
  return $child_lookups[$parent];
}