Chris@0: moduleHandler = $module_handler; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: protected function alterRoutes(RouteCollection $collection) { Chris@0: foreach ($collection as $name => $route) { Chris@0: if ($route->hasRequirement('_module_dependencies')) { Chris@0: $modules = $route->getRequirement('_module_dependencies'); Chris@0: Chris@0: $explode_and = $this->explodeString($modules, '+'); Chris@0: if (count($explode_and) > 1) { Chris@0: foreach ($explode_and as $module) { Chris@0: // If any moduleExists() call returns FALSE, remove the route and Chris@0: // move on to the next. Chris@0: if (!$this->moduleHandler->moduleExists($module)) { Chris@0: $collection->remove($name); Chris@0: continue 2; Chris@0: } Chris@0: } Chris@0: } Chris@0: else { Chris@0: // OR condition, exploding on ',' character. Chris@0: foreach ($this->explodeString($modules, ',') as $module) { Chris@0: if ($this->moduleHandler->moduleExists($module)) { Chris@0: continue 2; Chris@0: } Chris@0: } Chris@0: // If no modules are found, and we get this far, remove the route. Chris@0: $collection->remove($name); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Explodes a string based on a separator. Chris@0: * Chris@0: * @param string $string Chris@0: * The string to explode. Chris@0: * @param string $separator Chris@0: * The string separator to explode with. Chris@0: * Chris@0: * @return array Chris@0: * An array of exploded (and trimmed) values. Chris@0: */ Chris@0: protected function explodeString($string, $separator = ',') { Chris@0: return array_filter(array_map('trim', explode($separator, $string))); Chris@0: } Chris@0: Chris@0: }