/** * 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 getActionsForRoute($route_appears) { if (!isset($this->instances[$route_appears])) { $route_names = array(); $this->instances[$route_appears] = array(); // @todo - optimize this lookup by compiling or caching. foreach ($this->getDefinitions() as $plugin_id => $action_info) { if (in_array($route_appears, $action_info['appears_on'])) { $plugin = $this->createInstance($plugin_id); $route_names[] = $plugin->getRouteName(); $this->instances[$route_appears][$plugin_id] = $plugin; } } // Pre-fetch all the action route objects. This reduces the number of SQL // queries that would otherwise be triggered by the access manager. if (!empty($route_names)) { $this->routeProvider->getRoutesByNames($route_names); } } $links = array(); /** @var $plugin \Drupal\Core\Menu\LocalActionInterface */ foreach ($this->instances[$route_appears] as $plugin_id => $plugin) { $cacheability = new CacheableMetadata(); $route_name = $plugin->getRouteName(); $route_parameters = $plugin->getRouteParameters($this->routeMatch); $access = $this->accessManager->checkNamedRoute($route_name, $route_parameters, $this->account, TRUE); $links[$plugin_id] = array('#theme' => 'menu_local_action', '#link' => array('title' => $this->getTitle($plugin), 'url' => Url::fromRoute($route_name, $route_parameters), 'localized_options' => $plugin->getOptions($this->routeMatch)), '#access' => $access, '#weight' => $plugin->getWeight()); $cacheability->addCacheableDependency($access); // For backward compatibility in 8.0.x, plugins that do not implement // the \Drupal\Core\Cache\CacheableDependencyInterface are assumed // to be cacheable forever. if ($plugin instanceof CacheableDependencyInterface) { $cacheability->addCacheableDependency($plugin); } else { $cacheability->setCacheMaxAge(Cache::PERMANENT); } $cacheability->applyTo($links[$plugin_id]); } $links['#cache']['contexts'][] = 'route'; return $links; }
/** * Applies the values of this bubbleable metadata object to a render array. * * @param array &$build * A render array. */ public function applyTo(array &$build) { parent::applyTo($build); $build['#attached'] = $this->attachments; }
/** * Applies the values of this bubbleable metadata object to a render array. * * @param array &$build * A render array. */ public function applyTo(array &$build) { parent::applyTo($build); $build['#attached'] = $this->attached; $build['#post_render_cache'] = $this->postRenderCache; }