You are here

protected function RuleChainManager::sortChain in ThemeKey 8

1 call to RuleChainManager::sortChain()
RuleChainManager::setChain in src/RuleChainManager.php

File

src/RuleChainManager.php, line 114
Contains OperatorManager.

Class

RuleChainManager
ThemeKey Rule Chain manager.

Namespace

Drupal\themekey

Code

protected function sortChain($chain, $parent = NULL, $depth = 0) {
  $sorted_rules = array();
  $sorted_chain = array();
  foreach ($chain as $ruleId => $ruleMetaData) {
    if ($ruleMetaData['parent'] == $parent) {
      $sorted_rules[$ruleId] = $ruleMetaData['weight'];
    }
  }
  if (!empty($sorted_rules)) {
    asort($sorted_rules, SORT_NUMERIC);
    foreach (array_keys($sorted_rules) as $ruleId) {
      $sorted_chain[$ruleId] = $chain[$ruleId];
      $sorted_chain[$ruleId]['depth'] = $depth;
      $sorted_chain = array_merge($sorted_chain, $this
        ->sortChain($chain, $ruleId, $depth + 1));
    }
  }
  return $sorted_chain;
}