class TourHelpSection in Drupal 9
Same name and namespace in other branches
- 8 core/modules/tour/src/Plugin/HelpSection/TourHelpSection.php \Drupal\tour\Plugin\HelpSection\TourHelpSection
Provides the tours list section for the help page.
Plugin annotation
@HelpSection(
id = "tour",
title = @Translation("Tours"),
weight = 10,
description = @Translation("Tours guide you through workflows or explain concepts on various user interface pages. The tours with links in this list are on user interface landing pages; the tours without links will show on individual pages (such as when editing a View using the Views UI module). Available tours:"),
permission = "access tour"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase implements HelpSectionPluginInterface uses UnchangingCacheableDependencyTrait
- class \Drupal\tour\Plugin\HelpSection\TourHelpSection implements ContainerFactoryPluginInterface
- class \Drupal\help\Plugin\HelpSection\HelpSectionPluginBase implements HelpSectionPluginInterface uses UnchangingCacheableDependencyTrait
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of TourHelpSection
File
- core/
modules/ tour/ src/ Plugin/ HelpSection/ TourHelpSection.php, line 23
Namespace
Drupal\tour\Plugin\HelpSectionView source
class TourHelpSection extends HelpSectionPluginBase implements ContainerFactoryPluginInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a TourHelpSection object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getCacheMaxAge() {
// The calculation of which URL (if any) gets put on which tour depends
// on a route access check. This can have a lot of inputs, including user
// permissions and other factors. Rather than doing a complicated
// accounting of the cache metadata for all of these possible factors, set
// the max age of the cache to zero to prevent using incorrect cached
// information.
return 0;
}
/**
* {@inheritdoc}
*/
public function listTopics() {
/** @var \Drupal\tour\TourInterface[] $tours */
$tours = $this->entityTypeManager
->getStorage('tour')
->loadMultiple();
// Sort in the manner defined by Tour.
uasort($tours, [
'Drupal\\tour\\Entity\\Tour',
'sort',
]);
// Make a link to each tour, using the first of its routes that can
// be linked to by this user, if any.
$topics = [];
foreach ($tours as $tour) {
$title = $tour
->label();
$id = $tour
->id();
$routes = $tour
->getRoutes();
$made_link = FALSE;
foreach ($routes as $route) {
// Some tours are for routes with parameters. For instance, there is
// currently a tour in the Language module for the language edit page,
// which appears on all pages with URLs like:
// /admin/config/regional/language/edit/LANGCODE.
// There is no way to make a link to the page that displays the tour,
// because it is a set of pages. The easiest way to detect this is to
// use a try/catch exception -- try to make a link, and it will error
// out with a missing parameter exception if the route leads to a set
// of pages instead of a single page.
try {
$params = isset($route['route_params']) ? $route['route_params'] : [];
$url = Url::fromRoute($route['route_name'], $params);
// Skip this route if the current user cannot access it.
if (!$url
->access()) {
continue;
}
// Generate the link HTML directly, using toString(), to catch
// missing parameter exceptions now instead of at render time.
$topics[$id] = Link::fromTextAndUrl($title, $url)
->toString();
// If the line above didn't generate an exception, we have a good
// link that the user can access.
$made_link = TRUE;
break;
} catch (\Exception $e) {
// Exceptions are normally due to routes that need parameters. If
// there is an exception, just try the next route and see if we can
// find one that will work for us.
}
}
if (!$made_link) {
// None of the routes worked to make a link, so at least display the
// tour title.
$topics[$id] = $title;
}
}
return $topics;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
HelpSectionPluginBase:: |
public | function |
Returns the description text for the help section. Overrides HelpSectionPluginInterface:: |
|
HelpSectionPluginBase:: |
public | function |
Returns the title of the help section. Overrides HelpSectionPluginInterface:: |
|
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TourHelpSection:: |
protected | property | The entity type manager. | |
TourHelpSection:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
TourHelpSection:: |
public | function |
Overrides UnchangingCacheableDependencyTrait:: |
|
TourHelpSection:: |
public | function |
Returns a list of topics to show in the help section. Overrides HelpSectionPluginInterface:: |
|
TourHelpSection:: |
public | function |
Constructs a TourHelpSection object. Overrides PluginBase:: |
|
UnchangingCacheableDependencyTrait:: |
public | function | 1 | |
UnchangingCacheableDependencyTrait:: |
public | function | 1 |