You are here

function themekey_match_rule_childs in ThemeKey 7.3

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 themekey_base.inc \themekey_match_rule_childs()
  5. 7.2 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

$rules: array of matched rules

Return value

NULL in case of an error array containing the name of the theme if child rule matched and the cascade of parent rules matched FALSE if no child rule matches TRUE if no child properties in the chain

See also

themekey_match_rules()

3 calls to themekey_match_rule_childs()
themekey_css_init in themekey_css/themekey_css.module
Implements hook_init().
themekey_match_rules in ./themekey_base.inc
This function steps through the rule chain and returns a theme.
themekey_redirect_match_rules in themekey_redirect/themekey_redirect.module

File

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

Code

function themekey_match_rule_childs(&$parameters, $options, $parent = 0) {
  static $child_lookups = array();
  if (!$parent) {

    // reset
    $child_lookups = array();
  }
  if (isset($child_lookups[$parent])) {

    // prevent endless recursion in case of mal-formatted data in database
    return $child_lookups[$parent];
  }
  if ($result = db_select($options['table'], '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' => $options['format_rule_as_string_callback']($item->id),
          ));
        }
        $child_lookups[$parent] = themekey_match_rule_childs($parameters, $options, $item->id);
        if (FALSE === $child_lookups[$parent]) {
          continue;
        }
        elseif (TRUE === $child_lookups[$parent]) {
          if (isset($options['check_enabled_callback']) && !$options['check_enabled_callback']($item->theme)) {
            if (!empty($options['stop_on_check_enabled_false'])) {
              if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
                themekey_set_debug_message('Stop on same target: %theme', array(
                  '%theme' => $item->theme,
                ));
              }
              return FALSE;
            }
            if (variable_get('themekey_debug_trace_rule_switching', FALSE)) {
              themekey_set_debug_message('Target disabled or not found: %theme', array(
                '%theme' => $item->theme,
              ));
            }
            continue;
          }
          $rules[] = $item;
          $child_lookups[$parent] = array(
            'theme' => $item->theme,
            'rules_matched' => $rules,
          );

          // Extend returning array.
          if ($options['table'] == 'themekey_css_rules') {
            $child_lookups[$parent]['css_group'] = $item->css_group;
            $child_lookups[$parent]['css_weight'] = $item->css_weight;
          }
        }

        // 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' => $options['format_rule_as_string_callback']($item->id),
        ));
      }
    }
    $child_lookups[$parent] = !$num_childs;
    return $child_lookups[$parent];
  }
  $child_lookups[$parent] = NULL;
  return $child_lookups[$parent];
}