/** * Prints a page listing various types of help. * * The page has sections defined by \Drupal\help\HelpSectionPluginInterface * plugins. * * @return array * A render array for the help page. */ public function helpMain() { $output = []; // We are checking permissions, so add the user.permissions cache context. $cacheability = new CacheableMetadata(); $cacheability->addCacheContexts(['user.permissions']); $plugins = $this->helpManager->getDefinitions(); $cacheability->addCacheableDependency($this->helpManager); foreach ($plugins as $plugin_id => $plugin_definition) { // Check the provided permission. if (!empty($plugin_definition['permission']) && !$this->currentuser()->hasPermission($plugin_definition['permission'])) { continue; } // Add the section to the page. /** @var \Drupal\help\HelpSectionPluginInterface $plugin */ $plugin = $this->helpManager->createInstance($plugin_id); $this_output = ['#theme' => 'help_section', '#title' => $plugin->getTitle(), '#description' => $plugin->getDescription(), '#empty' => $this->t('There is currently nothing in this section.'), '#links' => []]; $links = $plugin->listTopics(); if (is_array($links) && count($links)) { $this_output['#links'] = $links; } $cacheability->addCacheableDependency($plugin); $output[$plugin_id] = $this_output; } $cacheability->applyTo($output); return $output; }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters, CacheableMetadata $cacheable_metadata = NULL) { if ($route_name === '<current>') { if ($current_route = $this->routeMatch->getRouteObject()) { $requirements = $current_route->getRequirements(); // Setting _method and _schema is deprecated since 2.7. Using // setMethods() and setSchemes() are now the recommended ways. unset($requirements['_method']); unset($requirements['_schema']); $route->setRequirements($requirements); $route->setPath($current_route->getPath()); $route->setSchemes($current_route->getSchemes()); $route->setMethods($current_route->getMethods()); $route->setOptions($current_route->getOptions()); $route->setDefaults($current_route->getDefaults()); $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all()); if ($cacheable_metadata) { $cacheable_metadata->addCacheContexts(['route']); } } else { // If we have no current route match available, point to the frontpage. $route->setPath('/'); } } }
/** * {@inheritdoc} */ public function process($text, $langcode) { $result = new FilterProcessResult($text); $metadata = new CacheableMetadata(); $metadata->addCacheTags(['merge:tag']); $metadata->addCacheContexts(['user.permissions']); $result = $result->merge($metadata); return $result; }
/** * {@inheritdoc} */ public function processOutbound($route_name, Route $route, array &$parameters, CacheableMetadata $cacheable_metadata = NULL) { if ($route_name === '<current>') { if ($current_route = $this->routeMatch->getRouteObject()) { $route->setPath($current_route->getPath()); $route->setRequirements($current_route->getRequirements()); $route->setOptions($current_route->getOptions()); $route->setDefaults($current_route->getDefaults()); $parameters = array_merge($parameters, $this->routeMatch->getRawParameters()->all()); if ($cacheable_metadata) { $cacheable_metadata->addCacheContexts(['route']); } } else { // If we have no current route match available, point to the frontpage. $route->setPath('/'); } } }
/** * Implements Drupal\Core\PathProcessor\InboundPathProcessorInterface::processOutbound(). */ public function processOutbound($path, &$options = array(), Request $request = NULL, CacheableMetadata $cacheable_metadata = NULL) { $url_scheme = 'http'; $port = 80; if ($request) { $url_scheme = $request->getScheme(); $port = $request->getPort(); } $languages = array_flip(array_keys($this->languageManager->getLanguages())); // Language can be passed as an option, or we go for current URL language. if (!isset($options['language'])) { $language_url = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_URL); $options['language'] = $language_url; } elseif (!is_object($options['language']) || !isset($languages[$options['language']->getId()])) { return $path; } $config = $this->config->get('language.negotiation')->get('url'); if ($config['source'] == LanguageNegotiationUrl::CONFIG_PATH_PREFIX) { if (is_object($options['language']) && !empty($config['prefixes'][$options['language']->getId()])) { $options['prefix'] = $config['prefixes'][$options['language']->getId()] . '/'; if ($cacheable_metadata) { $cacheable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL]); } } } elseif ($config['source'] == LanguageNegotiationUrl::CONFIG_DOMAIN) { if (is_object($options['language']) && !empty($config['domains'][$options['language']->getId()])) { // Save the original base URL. If it contains a port, we need to // retain it below. if (!empty($options['base_url'])) { // The colon in the URL scheme messes up the port checking below. $normalized_base_url = str_replace(array('https://', 'http://'), '', $options['base_url']); } // Ask for an absolute URL with our modified base URL. $options['absolute'] = TRUE; $options['base_url'] = $url_scheme . '://' . $config['domains'][$options['language']->getId()]; // In case either the original base URL or the HTTP host contains a // port, retain it. if (isset($normalized_base_url) && strpos($normalized_base_url, ':') !== FALSE) { list(, $port) = explode(':', $normalized_base_url); $options['base_url'] .= ':' . $port; } elseif ($url_scheme == 'http' && $port != 80 || $url_scheme == 'https' && $port != 443) { $options['base_url'] .= ':' . $port; } if (isset($options['https'])) { if ($options['https'] === TRUE) { $options['base_url'] = str_replace('http://', 'https://', $options['base_url']); } elseif ($options['https'] === FALSE) { $options['base_url'] = str_replace('https://', 'http://', $options['base_url']); } } // Add Drupal's subfolder from the base_path if there is one. $options['base_url'] .= rtrim(base_path(), '/'); if ($cacheable_metadata) { $cacheable_metadata->addCacheContexts(['languages:' . LanguageInterface::TYPE_URL, 'url.site']); } } } return $path; }
/** * {@inheritdoc} */ public function getLocalTasks($route_name, $level = 0) { if (!isset($this->taskData[$route_name])) { $cacheability = new CacheableMetadata(); $cacheability->addCacheContexts(['route']); // Look for route-based tabs. $this->taskData[$route_name] = ['tabs' => [], 'cacheability' => $cacheability]; if (!$this->requestStack->getCurrentRequest()->attributes->has('exception')) { // Safe to build tasks only when no exceptions raised. $data = []; $local_tasks = $this->getTasksBuild($route_name, $cacheability); foreach ($local_tasks as $tab_level => $items) { $data[$tab_level] = empty($data[$tab_level]) ? $items : array_merge($data[$tab_level], $items); } $this->taskData[$route_name]['tabs'] = $data; // Allow modules to alter local tasks. $this->moduleHandler->alter('menu_local_tasks', $this->taskData[$route_name], $route_name, $cacheability); $this->taskData[$route_name]['cacheability'] = $cacheability; } } if (isset($this->taskData[$route_name]['tabs'][$level])) { return ['tabs' => $this->taskData[$route_name]['tabs'][$level], 'route_name' => $route_name, 'cacheability' => $this->taskData[$route_name]['cacheability']]; } return ['tabs' => [], 'route_name' => $route_name, 'cacheability' => $this->taskData[$route_name]['cacheability']]; }
/** * {@inheritdoc} */ public function getCacheableMetadata($name) { $this->initiateContext(); $metadata = new CacheableMetadata(); if (!empty($this->domain)) { $metadata->addCacheContexts(['url.site', 'languages:language_interface']); } return $metadata; }