diff --git a/core/modules/help/config/install/help.topic.help.yml b/core/modules/help/config/install/help.topic.help.yml index a966c94..b898631 100644 --- a/core/modules/help/config/install/help.topic.help.yml +++ b/core/modules/help/config/install/help.topic.help.yml @@ -4,25 +4,8 @@ dependencies: { } id: help label: 'Help module' body: - value: > -

About

\r\n\r\n

The Help module provides - Help reference pages to guide you - through the use and configuration of modules. It is a starting point - for Drupal.org online - documentation pages that contain more extensive and up-to-date - information, are annotated with user-contributed comments, and serve as the - definitive reference point for all Drupal documentation. For more - information, see the - online - documentation for the Help module.

\r\n\r\n

Uses

\r\n\r\n
- \r\n\t
Providing a help reference
\r\n\t
The Help module displays - both static module-provided help and configured help topics on the main - Help page.
\r\n\t
Configuring help - topics
\r\n\t
You can add, edit, delete, and translate configure - help topics on the Help topics - administration page. The help topics that are listed in the Module help - section of the main Help page cannot be edited or deleted.
\r\n -
\r\n" - format: full_html + value: "

About

\r\n

The Help module provides Help reference pages to guide you through the use and configuration of modules. It is a starting point for Drupal.org online documentation pages that contain more extensive and up-to-date information, are annotated with user-contributed comments, and serve as the definitive reference point for all Drupal documentation. For more information, see the online documentation for the Help module.

\r\n

Uses

\r\n
\r\n
Providing a help reference
\r\n
The Help module displays both static module-provided help and configured help topics on the main Help page.
\r\n
Configuring help topics
\r\n
You can add, edit, delete, and translate configure help topics on the Help topics administration page. The help topics that are listed in the Module help section of the main Help page cannot be edited or deleted.
\r\n
\r\n" + format: help top_level: true related: { } +list_on: { } diff --git a/core/modules/help/config/schema/help.schema.yml b/core/modules/help/config/schema/help.schema.yml index 37f82d7..4922897 100644 --- a/core/modules/help/config/schema/help.schema.yml +++ b/core/modules/help/config/schema/help.schema.yml @@ -26,3 +26,8 @@ help.topic.*: label: 'Related topics' sequence: - type: string + list_on: + type: sequence + label: 'List on topics' + sequence: + - type: string diff --git a/core/modules/help/help.routing.yml b/core/modules/help/help.routing.yml index ba0bee9..3540943 100644 --- a/core/modules/help/help.routing.yml +++ b/core/modules/help/help.routing.yml @@ -17,10 +17,10 @@ help.page: entity.help_topic.canonical: path: '/admin/help-topic/{help_topic}' defaults: - _content: '\Drupal\help\Controller\HelpController::helpEntityView' + _entity_view: 'help_topic.full' _title: 'Help' requirements: - _permission: 'access administration pages' + _entity_access: 'help_topic.view' help.topic_admin: path: '/admin/config/development/help' diff --git a/core/modules/help/src/Controller/HelpController.php b/core/modules/help/src/Controller/HelpController.php index cf27ca8..0453375 100644 --- a/core/modules/help/src/Controller/HelpController.php +++ b/core/modules/help/src/Controller/HelpController.php @@ -11,10 +11,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Url; -use Drupal\Core\Utility\Token; use Drupal\Component\Utility\String; -use Drupal\help\Entity\HelpTopic; -use Drupal\help\HelpTopicInterface; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -38,26 +35,16 @@ class HelpController extends ControllerBase { protected $helpStorage; /** - * The token replacement service class. - * - * @var \Drupal\Core\Utility\Token - */ - protected $token; - - /** * Creates a new HelpController. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The current route match. * @param \Drupal\Core\Entity\EntityStorageInterface $help_storage * The entity storage for help topic entities. - * @param \Drupal\Core\Utility\Token $token - * The token replacement service class. */ - public function __construct(RouteMatchInterface $route_match, EntityStorageInterface $help_storage, Token $token) { + public function __construct(RouteMatchInterface $route_match, EntityStorageInterface $help_storage) { $this->routeMatch = $route_match; $this->helpStorage = $help_storage; - $this->token = $token; } /** @@ -66,8 +53,7 @@ public function __construct(RouteMatchInterface $route_match, EntityStorageInter public static function create(ContainerInterface $container) { return new static( $container->get('current_route_match'), - $container->get('entity.manager')->getStorage('help_topic'), - $container->get('token') + $container->get('entity.manager')->getStorage('help_topic') ); } @@ -234,56 +220,4 @@ public function helpPage($name) { throw new NotFoundHttpException(); } } - - /** - * Renders a help topic page from a configured help entity. - * - * @param \Drupal\help\HelpTopicInterface $help_topic - * The help entity to display. - * - * @return array - * A render array for the help topic page. - */ - public function helpEntityView(HelpTopicInterface $help_topic) { - $build = array(); - - $build['#title'] = String::checkPlain($help_topic->label()); - - $body = $help_topic->getBody(); - $build['body'] = array( - '#type' => 'processed_text', - '#text' => $this->token->replace($body['value']), - '#format' => $body['format'], - ); - - $related = $help_topic->getRelated(); - $links = array(); - foreach ($related as $other_id) { - if ($other_id != $help_topic->id()) { - $topic = $this->helpStorage->load($other_id); - if ($topic) { - $links[] = array( - 'title' => $topic->label(), - 'url' => $topic->urlInfo('canonical'), - ); - } - } - } - - if (count($links)) { - $build['related'] = array( - '#theme' => 'links', - '#heading' => array( - 'text' => $this->t('Related topics'), - 'level' => 'h3', - ), - '#links' => $links, - ); - } - - // @todo Also make a list of topics that list this one as "related"? - - return $build; - } - } diff --git a/core/modules/help/src/Entity/HelpTopic.php b/core/modules/help/src/Entity/HelpTopic.php index f84da2a..7c7131d 100644 --- a/core/modules/help/src/Entity/HelpTopic.php +++ b/core/modules/help/src/Entity/HelpTopic.php @@ -40,6 +40,7 @@ * "delete" = "Drupal\help\Form\HelpDeleteForm", * }, * "list_builder" = "Drupal\help\HelpListBuilder", + * "view_builder" = "Drupal\help\HelpViewBuilder", * "access" = "Drupal\help\HelpAccessControlHandler", * }, * entity_keys = { @@ -96,6 +97,13 @@ class HelpTopic extends ConfigEntityBase implements HelpTopicInterface { protected $related = array(); /** + * List of topics this one should be listed on. + * + * @var string[] + */ + protected $list_on = array(); + + /** * {@inheritdoc} */ public function getBody() { @@ -120,12 +128,27 @@ public function getRelated() { * {@inheritdoc} */ public function setRelated($topics) { - // $topics can be an array or a comma-separated string. + $topics = $this->cleanTopicList($topics); + $this->set('related', $topics); + + return $this; + } + + /** + * Cleans a list of topic IDs. + * + * @param string|array $topics + * Either an array of topic IDs or a comma-separated list in a string. + * + * @return array + * List of non-empty IDs from the input. + */ + protected function cleanTopicList($topics) { if (is_string($topics)) { $topics = explode(',', $topics); } - // Make a list of non-empty, trimmed IDs. + // Make a list of non-empty trimmed IDs. $tosave = array(); foreach ($topics as $item) { $item = trim($item); @@ -134,7 +157,22 @@ public function setRelated($topics) { } } - $this->set('related', $tosave); + return $tosave; + } + + /** + * {@inheritdoc} + */ + public function getListOn() { + return $this->get('list_on'); + } + + /** + * {@inheritdoc} + */ + public function setListOn($topics) { + $topics = $this->cleanTopicList($topics); + $this->set('list_on', $topics); return $this; } diff --git a/core/modules/help/src/Form/HelpTopicForm.php b/core/modules/help/src/Form/HelpTopicForm.php index 28c5441..e3252fe 100644 --- a/core/modules/help/src/Form/HelpTopicForm.php +++ b/core/modules/help/src/Form/HelpTopicForm.php @@ -104,13 +104,20 @@ public function form(array $form, FormStateInterface $form_state) { '#default_value' => implode(',', $this->entity->getRelated()), ); - $form['#entity_builders'][] = array($this, 'copyRelatedFieldToEntity'); + $form['list_on'] = array( + '#title' => $this->t('Topics to list this topic on'), + '#description' => $this->t('Comma-separated list of machine names of topics. This topic will be listed as Related on those topic pages.'), + '#type' => 'textarea', + '#default_value' => implode(',', $this->entity->getListOn()), + ); + + $form['#entity_builders'][] = array($this, 'copyTopicFieldsToEntity'); return parent::form($form, $form_state); } /** - * Copies the related topics field value to the entity property. + * Copies the topics field values to the entity properties. * * This is added to $form['#entity_builders'] in the form builder method. * @@ -123,8 +130,9 @@ public function form(array $form, FormStateInterface $form_state) { * @param \Drupal\Core\Form\FormStateInterface $form_state * Form state. */ - protected function copyRelatedFieldToEntity($type, EntityInterface $entity, array &$form, FormStateInterface &$form_state) { + protected function copyTopicFieldsToEntity($type, EntityInterface $entity, array &$form, FormStateInterface &$form_state) { $entity->setRelated($form_state->getValue('related')); + $entity->setListOn($form_state->getValue('list_on')); } /** diff --git a/core/modules/help/src/HelpTopicInterface.php b/core/modules/help/src/HelpTopicInterface.php index 0169ded..978aec6 100644 --- a/core/modules/help/src/HelpTopicInterface.php +++ b/core/modules/help/src/HelpTopicInterface.php @@ -42,14 +42,33 @@ public function isTopLevel(); public function getRelated(); /** - * Sets the related topics + * Sets the related topics. * * @param string|array - * Either an array of related topic IDS, or a comma-separated list of + * Either an array of related topic IDs, or a comma-separated list of * related topic IDs. * * @return $this */ public function setRelated($topics); + /** + * Returns the IDs of topics this should be listed on. + * + * @return array + * Array of the IDs of topics that should list this one as "related". + */ + public function getListOn(); + + /** + * Sets the list on topics. + * + * @param string|array + * Either an array of topic IDs, or a comma-separated list of topic IDs; + * this topic should be listed as Related on those topic pages. + * + * @return $this + */ + public function setListOn($topics); + } diff --git a/core/modules/help/src/Tests/HelpTest.php b/core/modules/help/src/Tests/HelpTest.php index 8e4548b..50794ba 100644 --- a/core/modules/help/src/Tests/HelpTest.php +++ b/core/modules/help/src/Tests/HelpTest.php @@ -131,6 +131,7 @@ protected function verifyHelpLinks() { 'link to the help admin page' => 'Add new help topic', 'Help module' => 'The Help module provides', 'Linked topic' => 'This topic is not supposed to be top-level', + 'Additional topic' => 'This topic should get listed automatically', ); foreach ($links as $link_text => $page_text) { $this->drupalGet($page); @@ -138,9 +139,10 @@ protected function verifyHelpLinks() { $this->assertText($page_text); } - // Verify that the non-top-level topic does not appear on the Help page. + // Verify that the non-top-level topics do not appear on the Help page. $this->drupalGet('admin/help'); $this->assertNoLink('Linked topic'); + $this->assertNoLink('Additional topic'); } /** diff --git a/core/modules/help/test/modules/help_test/config/install/help.topic.help_test.yml b/core/modules/help/test/modules/help_test/config/install/help.topic.help_test.yml index bb092f6..f7ad029 100644 --- a/core/modules/help/test/modules/help_test/config/install/help.topic.help_test.yml +++ b/core/modules/help/test/modules/help_test/config/install/help.topic.help_test.yml @@ -5,8 +5,9 @@ id: help_test label: 'Help Test module' body: value: 'This is a test. It should link to the Help module topic, and it should link to the help admin page. Also there should be a related topic link below to the Help module topic page and the linked topic.' - format: basic_html + format: help top_level: true related: - help - help_test_linked +list_on: { } diff --git a/core/modules/help/test/modules/help_test/config/install/help.topic.help_test_linked.yml b/core/modules/help/test/modules/help_test/config/install/help.topic.help_test_linked.yml index 0a557b0..8d3674c 100644 --- a/core/modules/help/test/modules/help_test/config/install/help.topic.help_test_linked.yml +++ b/core/modules/help/test/modules/help_test/config/install/help.topic.help_test_linked.yml @@ -5,6 +5,7 @@ id: help_test_linked label: 'Linked topic' body: value: 'This topic is not supposed to be top-level.' - format: basic_html + format: help top_level: false related: { } +list_on: { }