diff --git a/core/modules/help_topics/help_topics.info.yml b/core/modules/help_topics/help_topics.info.yml index fd909f33d1..57e822d327 100644 --- a/core/modules/help_topics/help_topics.info.yml +++ b/core/modules/help_topics/help_topics.info.yml @@ -1,9 +1,8 @@ name: Help Topics type: module -description: 'Displays and configures help topics' +description: 'Displays help topics provided by themes and modules.' core: 8.x package: Core (Experimental) -configure: entity.help_topic.collection version: VERSION dependencies: - drupal:help diff --git a/core/modules/help_topics/help_topics.module b/core/modules/help_topics/help_topics.module index a472f3ebb7..0b0916bf41 100644 --- a/core/modules/help_topics/help_topics.module +++ b/core/modules/help_topics/help_topics.module @@ -2,7 +2,7 @@ /** * @file - * Provides configurable help topics. + * Displays help topics provided by modules and themes. */ use Drupal\Core\Routing\RouteMatchInterface; @@ -22,13 +22,13 @@ function help_topics_help($route_name, RouteMatchInterface $route_match) { $output .= '
' . t('See the Help page for more topics.', [ - ':help_page' => Url::fromRoute('help.main')->toString() + ':help_page' => Url::fromRoute('help.main')->toString(), ]) . '
'; } } diff --git a/core/modules/help_topics/src/Controller/AutocompleteController.php b/core/modules/help_topics/src/Controller/AutocompleteController.php deleted file mode 100644 index 2ffcf2ace7..0000000000 --- a/core/modules/help_topics/src/Controller/AutocompleteController.php +++ /dev/null @@ -1,244 +0,0 @@ -pluginManager = $plugin_manager; - $this->modules = $modules; - $this->moduleHandler = $module_handler; - $this->themeHandler = $theme_handler; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.help_topic'), - $container->get('extension.list.module'), - $container->get('module_handler'), - $container->get('theme_handler') - ); - } - - /** - * Retrieves suggestions for help topic autocomplete. - * - * The autocomplete suggestions search for matches by topic title and machine - * name, and are returned in a JSON response for use in an edit form field. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - * A JSON response containing the autocomplete suggestions. - */ - public function topicAutocomplete(Request $request) { - $matches = []; - $count = 0; - if ($input = $this->getUserInput($request)) { - $topics = $this->pluginManager->findMatches($input); - if (!empty($topics)) { - foreach ($topics as $title => $id) { - $matches[] = $this->getMatch($id, $title); - $count++; - if ($count >= 10) { - break; - } - } - } - } - - return new JsonResponse($matches); - } - - /** - * Retrieves suggestions for module autocomplete. - * - * The autocomplete suggestions search for matches by module displayed and - * machine name, and they are returned in a JSON response for use in an edit - * form field. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - * A JSON response containing the autocomplete suggestions. - */ - public function moduleAutocomplete(Request $request) { - $matches = []; - if ($input = $this->getUserInput($request)) { - // Return only first 10 matches. - $limit = 10; - foreach ($this->getActiveModules() as $name => $label) { - // Add as a match if the typed text matches machine name or displayed - // name. - if (stripos($name, $input) !== FALSE || stripos($label, $input) !== FALSE) { - $matches[] = $this->getMatch($name, $label); - if (!--$limit) { - break; - } - } - } - } - return new JsonResponse($matches); - } - - /** - * Retrieves suggestions for theme autocomplete. - * - * The autocomplete suggestions search for matches by theme displayed and - * machine name, and they are returned in a JSON response for use in an edit - * form field. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - * - * @return \Symfony\Component\HttpFoundation\JsonResponse - * A JSON response containing the autocomplete suggestions. - */ - public function themeAutocomplete(Request $request) { - $matches = []; - if ($input = $this->getUserInput($request)) { - // Return only first 10 matches. - $limit = 10; - foreach ($this->getThemes() as $name => $label) { - // Add as a match if the typed text matches machine name or displayed - // name. - if (strpos($name, $input) !== FALSE || strpos($label, $input) !== FALSE) { - $matches[] = $this->getMatch($name, $label); - if (!--$limit) { - break; - } - } - } - } - return new JsonResponse($matches); - } - - /** - * Returns the last typed tag from user input passed to autocomplete. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The request object. - * - * @return string - * The last tag. - */ - protected function getUserInput(Request $request) { - $input = $request->query->get('q'); - if (!$input) { - return ''; - } - $input = Tags::explode($input); - return mb_strtolower(array_pop($input)); - } - - /** - * Builds the structure to display in an autocomplete dropdown. - * - * @param string $value - * Machine name to display and use as the value. - * @param string $label - * Human-readable name to display. - * - * @return array - * An array of matched labels, in the format required by the Ajax - * autocomplete API (array('value' => $value, 'label' => $label)). - */ - protected function getMatch($value, $label) { - return [ - 'value' => $value, - 'label' => new HtmlEscapedText("$label ($value)"), - ]; - } - - /** - * Returns the list of active modules' names. - * - * @return array - * An associative array of active modules' human names keyed by module name. - */ - protected function getActiveModules() { - $all = $this->modules->getAllAvailableInfo(); - $installed = array_keys($this->moduleHandler->getModuleList()); - $modules = []; - foreach ($installed as $extension) { - $modules[$extension] = $all[$extension]['name']; - } - // Modules are sorted by their weight so sort them by names. - asort($modules); - return $modules; - } - - /** - * Returns the list of installed themes' names. - * - * @return array - * An associative array of theme names keyed by machine name of the theme. - */ - protected function getThemes() { - // There is not an obvious way to query installed themes. So make - // a list of all themes, and filter it down to ones that match. - $installed = $this->themeHandler->listInfo(); - $themes = []; - foreach ($installed as $name => $extension) { - $themes[$name] = $extension->info['name']; - } - // Themes are sorted by file system discovery so sort them by name. - asort($themes); - return $themes; - } - -} diff --git a/core/modules/help_topics/src/Controller/HelpTopicPluginController.php b/core/modules/help_topics/src/Controller/HelpTopicPluginController.php index 39eae8f0be..8add59ebce 100644 --- a/core/modules/help_topics/src/Controller/HelpTopicPluginController.php +++ b/core/modules/help_topics/src/Controller/HelpTopicPluginController.php @@ -66,8 +66,9 @@ public static function create(ContainerInterface $container) { /** * Displays a help topic page. * - * @param $id - * The plugin id. Maps to the {id} placeholder in the help_topics.help_topic route. + * @param string $id + * The plugin id. Maps to the {id} placeholder + * in the help_topics.help_topic route. * * @return array * A render array with the contents of a help topic page. @@ -75,7 +76,7 @@ public static function create(ContainerInterface $container) { public function viewHelpTopic($id) { $build = []; - /** @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $help_topic */ + /* @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $help_topic */ $help_topic = $this->helpTopicPluginManager->createInstance($id); $body = $help_topic->getBody(); diff --git a/core/modules/help_topics/src/HtmlChunker.php b/core/modules/help_topics/src/HtmlChunker.php index e62419a554..e87ee010ad 100644 --- a/core/modules/help_topics/src/HtmlChunker.php +++ b/core/modules/help_topics/src/HtmlChunker.php @@ -25,7 +25,7 @@ class HtmlChunker { * * @see \Drupal\help_topics\HtmlChunker::joinChunks() */ - public static function chunkHTML($html) { + public static function chunkHtml($html) { $dom = Html::load($html); if (!$dom) { return FALSE; @@ -51,9 +51,9 @@ public static function chunkHTML($html) { * @return string * HTML string containing all of the chunks. * - * @see \Drupal\help_topics\HtmlChunker::chunkHTML() + * @see \Drupal\help_topics\HtmlChunker::chunkHtml() */ - public static function joinChunks($chunks) { + public static function joinChunks(array $chunks) { $text = ''; foreach ($chunks as $chunk) { $text .= $chunk['prefix_tags'] . $chunk['text'] . $chunk['suffix_tags']; diff --git a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php index f4dab75fdf..8dfabf577e 100644 --- a/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php +++ b/core/modules/help_topics/src/Plugin/HelpSection/HelpTopicSection.php @@ -13,7 +13,7 @@ * @HelpSection( * id = "help_topics", * title = @Translation("Topics"), - * description = @Translation("Topics can be provided by modules, themes, installation profiles, or site administrators, and they may be organized hierarchically. Top-level help topics configured on your site:"), + * description = @Translation("Topics can be provided by modules or themes. Top-level help topics configured on your site:"), * permission = "view help topics" * ) */ diff --git a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php index 931102be38..f5e4720d88 100644 --- a/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php +++ b/core/modules/help_topics/src/Plugin/HelpTopic/HelpTopicPluginManager.php @@ -15,9 +15,6 @@ * Modules and themes can provide help topics in YAML files called * name_of_topic.help_topic.yml inside the module or theme sub-directory * help_topics. - * - * The format of this file is the same as for the help topic entity. See - * config/schema/help_topics.schema.yml */ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPluginManagerInterface { @@ -27,9 +24,9 @@ class HelpTopicPluginManager extends DefaultPluginManager implements HelpTopicPl * @var array */ protected $defaults = [ - // The plugin ID. Set by the plugin system based on the top-level YAML key + // The plugin ID. Set by the plugin system based on the top-level YAML key. 'id' => '', - // The title of the help topic plugin + // The title of the help topic plugin. 'label' => '', // Whether or not the topic should appear on the help topics list. 'top_level' => '', @@ -95,10 +92,10 @@ public function __construct(ModuleHandlerInterface $module_handler, ThemeHandler * * @param array $definition * The definition to be processed and modified by reference. - * @param $plugin_id + * @param string $plugin_id * The ID of the plugin this definition is being used for. */ - public function processDefinition(&$definition, $plugin_id) { + public function processDefinition(array &$definition, $plugin_id) { $definition = NestedArray::mergeDeep($this->defaults, $definition); $definition['id'] = $plugin_id; } @@ -141,7 +138,7 @@ protected function getFactory() { */ public function getDefinitions() { // Since this function is called rarely, instantiate the discovery here. - // This finds all the help_topic plugins in theme and module directories + // This finds all the help_topic plugins in theme and module directories. $definitions = $this->getDiscovery()->getDefinitions(); foreach ($definitions as $plugin_id => &$definition) { @@ -171,7 +168,7 @@ public function getTopLevelTopics() { foreach ($this->getDefinitions() as $definition) { if ($definition['top_level']) { - /** @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $topic **/ + /* @var \Drupal\help_topics\Plugin\HelpTopic\HelpTopicPluginInterface $topic */ $topic = $this->createInstance($definition['id']); $label = (string) $topic->getLabel(); diff --git a/core/modules/help_topics/tests/src/Functional/HelpTopicTest.php b/core/modules/help_topics/tests/src/Functional/HelpTopicTest.php index 69cf5357aa..94969a2a31 100644 --- a/core/modules/help_topics/tests/src/Functional/HelpTopicTest.php +++ b/core/modules/help_topics/tests/src/Functional/HelpTopicTest.php @@ -85,12 +85,12 @@ public function testHelp() { $this->drupalGet('admin/help'); $session = $this->assertSession(); $session->responseContains('