Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. HelpTwigExtension.php

function HelpTwigExtension::getTopicLink

Returns a link to a help topic, or the title of the topic.

Parameters

string $topic_id: The help topic ID.

Return value

array A render array with a generated absolute link to the given topic. If the user does not have permission to view the topic, or an exception occurs, such as the topic not being defined due to a module not being installed, a default string is returned.

See also

\Drupal\Core\Template\TwigExtension::getUrl()

File

core/modules/help/src/HelpTwigExtension.php, line 122

Class

HelpTwigExtension
Defines and registers Drupal Twig extensions for rendering help topics.

Namespace

Drupal\help

Code

public function getTopicLink(string $topic_id) : array {
    assert($this->pluginManager instanceof HelpTopicPluginManagerInterface, "The plugin manager hasn't been set up. Any configuration YAML file with a service directive dealing with the Twig configuration can cause this, most likely found in a recently installed or changed module.");
    $bubbles = new BubbleableMetadata();
    $bubbles->addCacheableDependency($this->pluginManager);
    try {
        $plugin = $this->pluginManager
            ->createInstance($topic_id);
    } catch (PluginNotFoundException) {
        // Not a topic.
        $plugin = FALSE;
    }
    if ($plugin) {
        $parameters = [
            'id' => $topic_id,
        ];
        $route = 'help.help_topic';
        $build = $this->getRouteLink($plugin->getLabel(), $route, $parameters);
        $bubbles->addCacheableDependency($plugin);
    }
    else {
        $build = [
            '#markup' => $this->t('Missing help topic %topic', [
                '%topic' => $topic_id,
            ]),
        ];
    }
    $bubbles->applyTo($build);
    return $build;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal