Updated: Comment #0

Problem/Motivation

As spotted by @rszrama when testing #323926: Settings for non-existent theme, help text from hook_help() implementations is still displayed on 404 (and potentially 403) pages.

Proposed resolution

Don't display help text on 404 or 403 pages.

Remaining tasks

Write patch.
Write tests.

User interface changes

Help text for a given path won't be displayed if the page is a 403 or 404 page.

API changes

n/a

#323926: Settings for non-existent theme

Comments

star-szr’s picture

Issue tags: +Novice

This seems Novice-able to me.

ivan zugec’s picture

Status: Active » Needs review
StatusFileSize
new3.42 KB

Here's a first-pass at the patch.

Status: Needs review » Needs work
Issue tags: -Novice

The last submitted patch, hook_help_404-2073121-2.patch, failed testing.

ivan zugec’s picture

Status: Needs work » Needs review

#2: hook_help_404-2073121-2.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, hook_help_404-2073121-2.patch, failed testing.

simanjan’s picture

Status: Needs work » Needs review
Issue tags: +Novice

#2: hook_help_404-2073121-2.patch queued for re-testing.

star-szr’s picture

Nice, @Ivan Zugec!

Maybe a test-only version of the patch would be nice like on https://drupal.org/contributor-tasks/write-tests.

+++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
@@ -259,4 +259,17 @@ function testInvalidTheme() {
+
+  /**
+   * Ensure that the help text block is hidden on a 404 page error.
+   */
+  function testThemeSettingsNotFoundHelpText() {
+    // Ensure invalid theme settings form URLs return a proper 404.
+    $this->drupalGet('admin/appearance/settings/' . $this->randomName());
+    $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
+    // Ensure help block does not display.
+    $help_block = $this->xpath("//div[@id='block-help']");
+    $this->assertFalse($help_block, 'The help block is not displayed.');
+
+  }

Extra blank line at the end of this test method :)

ivan zugec’s picture

Assigned: Unassigned » ivan zugec

Thanks for the feedback, I'll fix it.

ivan zugec’s picture

StatusFileSize
new1.29 KB
ivan zugec’s picture

@Cotter, I have removed the extra blank line and created a separate patch just for the test.

Oh, and ignore comment #9 I slipped and clicked on the save button. :(

yingtho’s picture

I have testede it and it works as expected. But the test doesn't fail as expected due to the fact that the simpletest run on the admin page only get the content region and the rest of the region is empty. And therefor the test won't fail. I would mark this review "Reviewed and testede by the community" but not sure when the test doesn't work. What is the procedure?

webchick’s picture

Issue summary: View changes
Priority: Normal » Major
Status: Needs review » Needs work

I agree a failing test would be nice here.

Tentatively raising to major. While this doesn't expose anything too badly in Drupal core, it's possible custom modules add sensitive, admin-specific help text and showing that to anonymous users would be un-good.

dsdeiz’s picture

StatusFileSize
new3.52 KB

Not sure how to make the test fail as well. I think this is because the tests uses the Stark theme and "System help" block isn't placed (at least when I tried it). Anyway, just re-rolling the patch.

olli’s picture

linl’s picture

Status: Needs work » Needs review

Setting to "Needs review" so that testbot can run test for patch in #13.

olli’s picture

Status: Needs review » Needs work

I tried this with simplytest and it does not seem to fix the problem for admin/structure/block.

Also, node system uses hook_help() to display submission guidelines on node/add and node/edit. I tried this and could see the guidelines on access denied page.

#1969270: 403/404 pages: drupal_get_http_header('Status') returns no status code at all looks related.

dawehner’s picture

In general using current_path() is also probably wrong, you should better get it from the request object directly.

internetdevels’s picture

Assigned: ivan zugec » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.22 KB
new3.98 KB

I'v replaced curent_path() and found way how to obtain Status. Not sure my fix is good but it works.

dawehner’s picture

  1. +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php
    @@ -78,6 +78,10 @@ public static function create(ContainerInterface $container, array $configuratio
    +    if ($exception && in_array($exception->getStatusCode(), array(403, 404))) {
    +      return FALSE;
    +    }
    

    Could it be that we want to show the help text just on 200? Note: \Symfony\Component\HttpFoundation\Response has some constants we could leverage

  2. +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
    @@ -259,4 +259,16 @@ function testInvalidTheme() {
    +  function testThemeSettingsNotFoundHelpText() {
    

    Let's make the test method public.

  3. +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
    @@ -259,4 +259,16 @@ function testInvalidTheme() {
    +    // Ensure invalid theme settings form URLs return a proper 404.
    +    $this->drupalGet('admin/appearance/settings/' . $this->randomName());
    +    $this->assertResponse(404, 'The theme settings form URL for a non-existent theme could not be found.');
    ...
    +    $help_block = $this->xpath("//div[@id='block-help']");
    +    $this->assertFalse($help_block, 'The help block is not displayed.');
    ...
    +    // Ensure help block does not display.
    
    +++ b/core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php
    --- a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
    +++ b/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
    
    index 554450a..8f3698e 100644
    --- a/core/modules/system/lib/Drupal/system/Tests/System/ThemeTest.php
    

    I think we should move this test to some help related test and maybe use a more generic path or even better a unit test.

star-szr’s picture

Assigned: Unassigned » star-szr

Working on this.

star-szr’s picture

Assigned: star-szr » Unassigned
StatusFileSize
new4.77 KB
new3.38 KB

I tried to figure out how to do #19.1 but couldn't quite get there. @dawehner maybe you have a hint for us? :)

So here's an attempt at moving the test to a more logical place and expanding the coverage a bit to another one of the identified bug cases.

Edit: fixed typo.

star-szr’s picture

StatusFileSize
new2.08 KB

Forgot to include a test-only patch, and this should get things back to needs work anyway :)

The last submitted patch, 21: 2073121-21.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 22: 2073121-21-testonly.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.71 KB

What about something like this?

sutharsan’s picture

Added dawehner's #25 comment to #21 patch.

#19.3

... and maybe use a more generic path or even better a unit test.

I don't know how to make a unit test for this.

Status: Needs review » Needs work

The last submitted patch, 26: drupal-404-help-text-2073121-25-tests-only--must-fail.patch, failed testing.

The last submitted patch, 26: drupal-404-help-text-2073121-25-tests-only--must-fail.patch, failed testing.

sutharsan’s picture

Status: Needs work » Needs review

Back to needs review. Only the patch without the change failed.

[edit] typo

smira’s picture

Assigned: Unassigned » smira

rerolling

smira’s picture

StatusFileSize
new5.13 KB

rerolled patch to fix conflicts

error: patch failed: core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php:90
error: core/modules/system/lib/Drupal/system/Plugin/Block/SystemHelpBlock.php: patch does not apply
webchick’s picture

Status: Needs review » Closed (duplicate)

Oh shoot. I'm really sorry but I already committed this in another issue. :( #2245783: Regression: Help blocks display on 403/404 page Somehow this issue got missed.