You are here

protected function HelpTopicSection::getPlugins in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php \Drupal\help_topics\Plugin\HelpSection\HelpTopicSection::getPlugins()

Gets the top level help topic plugins.

Return value

\Drupal\help_topics\HelpTopicPluginInterface[] The top level help topic plugins.

2 calls to HelpTopicSection::getPlugins()
HelpTopicSection::getCacheMetadata in core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php
Gets the merged CacheableMetadata for all the top level help topic plugins.
HelpTopicSection::listTopics in core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php
Returns a list of topics to show in the help section.

File

core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php, line 169

Class

HelpTopicSection
Provides the help topics list section for the help page.

Namespace

Drupal\help_topics\Plugin\HelpSection

Code

protected function getPlugins() {
  if (!isset($this->topLevelPlugins)) {
    $definitions = $this->pluginManager
      ->getDefinitions();

    // Get all the top level topics and merge their list cache tags.
    foreach ($definitions as $definition) {
      if ($definition['top_level']) {
        $this->topLevelPlugins[$definition['id']] = $this->pluginManager
          ->createInstance($definition['id']);
      }
    }

    // Sort the top level topics by label and, if the labels match, then by
    // plugin ID.
    usort($this->topLevelPlugins, function (HelpTopicPluginInterface $a, HelpTopicPluginInterface $b) {
      $a_label = (string) $a
        ->getLabel();
      $b_label = (string) $b
        ->getLabel();
      if ($a_label === $b_label) {
        return $a
          ->getPluginId() < $b
          ->getPluginId() ? -1 : 1;
      }
      return strnatcasecmp($a_label, $b_label);
    });
  }
  return $this->topLevelPlugins;
}