/** * @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); }
/** * 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 string[][][] $candidates_all * Format: $['parent'|'title'][][$candidateKey] = $candidate * @param crumbs_Container_WeightMap $weightMap */ private function addCandidateCells(array $candidates_all, $weightMap) { foreach ($candidates_all as $type => $candidates_type) { foreach ($candidates_type as $i => $candidates) { $path = $this->paths[$i]; $item = $this->trail[$path]; $bestCandidateKey = $weightMap->findBestCandidateKey($candidates); foreach ($candidates as $candidateKey => $candidate) { $this->addCandidateCell($candidate, $type, $i, $candidateKey, $bestCandidateKey); } if ($type === 'parent') { $defaultCandidate = isset($paths[$i + 1]) ? $paths[$i + 1] : NULL; } else { $defaultCandidate = isset($item['title']) ? $item['title'] : NULL; } $this->addCandidateCell($defaultCandidate, $type, $i, NULL, $bestCandidateKey); } } }