/** * Invoke all relevant plugins to find title or parent for a given path. * * @param crumbs_PluginSystem_PluginMethodIterator $iterator * @param array $args * Parameter values to pass to plugin methods. * @param bool $processFindParent * * @return mixed|null */ protected function find($iterator, $args, $processFindParent = FALSE) { $best_candidate = NULL; $best_candidate_weight = 999999; $best_candidate_key = NULL; foreach ($iterator as $plugin_key => $position) { if (!$position instanceof crumbs_PluginSystem_PluginMethodIteratorPosition) { continue; } if ($position->isMultiPlugin()) { $localWeightMap = $this->weightMap->localWeightMap($plugin_key); if ($best_candidate_weight <= $localWeightMap->smallestValue()) { return $best_candidate; } $candidates = $position->invokeFinderMethod($args); if (empty($candidates)) { continue; } foreach ($candidates as $candidate_key => $candidate_raw) { if (!isset($candidate_raw)) { continue; } $candidate_weight = $localWeightMap->valueAtKey($candidate_key); if (FALSE === $candidate_weight) { continue; } if ($best_candidate_weight <= $candidate_weight) { continue; } if ($processFindParent) { $candidate = $this->processFindParent($candidate_raw); if (!isset($candidate)) { continue; } } else { $candidate = $candidate_raw; } $best_candidate = $candidate; $best_candidate_weight = $candidate_weight; } } elseif ($position->isMonoPlugin()) { $candidate_weight = $this->weightMap->valueAtKey($plugin_key); if ($best_candidate_weight <= $candidate_weight) { return $best_candidate; } $candidate_raw = $position->invokeFinderMethod($args); if (!isset($candidate_raw)) { continue; } $candidate = $processFindParent ? $this->processFindParent($candidate_raw) : $candidate_raw; if (isset($candidate)) { $best_candidate = $candidate; $best_candidate_weight = $candidate_weight; } } } return $best_candidate; }
/** * @param crumbs_Container_WeightMap $localWeightMap */ function initWeights($localWeightMap) { if ('user' !== $this->entityType) { return; } foreach (user_roles(TRUE) as $rid => $role) { $weight = $localWeightMap->valueAtKey($role); if (FALSE !== $weight) { $this->weights[$rid] = $weight; } } asort($this->weights); }