Problem/Motivation

contact_menu_local_tasks_alter() accesses $data['tabs'][0] unconditionally, but that might not exist.

Specifically if someone alters the other tabs away.

I hit this bug due to another bug, where Drupal was trying to render the local tasks on a maintenance page in which case there are no local tasks (will open a separate bug for that).

Proposed resolution

Add a check for isset($data['tabs'][0]).

Remaining tasks

Convert to an MR.

User interface changes

N/A

API changes

N/A

Issue fork drupal-2479449

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tstoeckler’s picture

Status: Active » Needs review
StatusFileSize
new669 bytes

Here we go.

larowlan’s picture

Status: Needs review » Reviewed & tested by the community
xjm’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs tests

If there is a bug exposed by this, we should presumably have tests? Thanks!

andypost’s picture

Issue tags: +Novice

and yep that needs tests

+++ b/core/modules/contact/contact.module
@@ -99,7 +99,7 @@ function contact_entity_extra_field_info() {
+  if (($route_name == 'entity.user.canonical') && isset($data['tabs'][0])) {

probably Element:children($data[tabs])

alimac’s picture

I would like to add a test, but I am not sure what to test for. Can someone point me in the right direction?

alimac’s picture

I found this test in contact/src/Tests/ContactPersonalTest.php:

    // Test that the 'contact tab' does not appear on the user profiles
    // for users without an email address configured.
    $this->drupalGet('user/' . $this->contactUser->id());
    $contact_link = '/user/' . $this->contactUser->id() . '/contact';
    $this->assertResponse(200);
    $this->assertNoLinkByHref ($contact_link, 'The "contact" tab is hidden on profiles for users with no email address');

I think the test would have to unset the tabs, then visit the user contact page and make sure it loads OK (200).

yesct’s picture

so, when @andypost mentions Element:children($data[tabs])
maybe that is a hint that this doesn't have to be a simpletest with a drupalsite, and can be a phpunit test on the output of the method?

dawehner’s picture

If you look at menu_local_tasks() there is the chance that $data['tabs'][0] is empty indeed.

I think the test would have to unset the tabs, then visit the user contact page and make sure it loads OK (200).

I mean it is really hard to trigger because /user/{user} is either accessible, so is the tab, or we result in a 403,
in which case $route_name is 'system.403', so I doubt you can ever run into that case in real life.

I hit this bug due to another bug, where Drupal was trying to render the local tasks on a maintenance page in which case there are no local tasks (will open a separate bug for that).

Do you mind pasting an URL to that? Why do we even try to produce local tasks on the maintenance page.

tstoeckler’s picture

I'm able to reproduce this, if I enable maintenance mode and then hit /user/1 as an anonymous user.

Not sure whether we should test that specifically, though, because that is quite specific to the "tabs on maintenance page" problem.

The problem is that template_preprocess_page() checks for the MAINTENANCE_MODE constant before fetching local tasks and tabs, but that is only defined in install.php and authorize.php, not during the normal maintenance mode.

@dawehner do you have thoughts on this?

tatisilva’s picture

StatusFileSize
new1008 bytes

Wrote phpunit test which tests for the undefined index. This is the opposite of what we actually want the test to do but could not figure how to test for a missing undefined index notice.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

@tatisilva this test should be in .patch format

andypost’s picture

Version: 8.6.x-dev » 8.8.x-dev

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

akashkumar07’s picture

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

I have changed the format from .txt to .patch. Hope, this will solve the issue.

andypost’s picture

Looks good start!

+++ b/core/modules/contact/tests/src/Unit/ContactTest.php
@@ -0,0 +1,37 @@
+class ContactTest extends UnitTestCase {

I bet you need to add contact module to the list of installed ones

akashkumar07’s picture

StatusFileSize
new1014 bytes

Status: Needs review » Needs work

The last submitted patch, 22: 2479449-22.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

akashkumar07’s picture

StatusFileSize
new1.12 KB

Hope, this patch would fix the issue.

akashkumar07’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: 2479449-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rithesh bk’s picture

Assigned: Unassigned » rithesh bk

currently i am working on it ....

rithesh bk’s picture

Assigned: rithesh bk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.12 KB

Please review it..... i have updated the patch .....

Status: Needs review » Needs work

The last submitted patch, 28: 2479449-28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rithesh bk’s picture

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

Please find the updated patch ..

Status: Needs review » Needs work

The last submitted patch, 30: 2479449-29.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rpayanm’s picture

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

Status: Needs review » Needs work

The last submitted patch, 32: 2479449-32.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

rpayanm’s picture

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

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

larowlan’s picture

Status: Needs review » Needs work

We've now got a test only file, but no fix.

And the test-only file doesn't fail.

Can someone confirm if this issue still exists?

sudiptadas19 made their first commit to this issue’s fork.

sudiptadas19’s picture

Status: Needs work » Needs review

Add isset checking for tabs and corresponding test cases in MR 346. Please review the changes.

larowlan’s picture

Status: Needs review » Needs work

I think we're probably better to remove that test and try to test it using the maintenance page approach per the issue summary steps to reproduce

larowlan’s picture

Yeap, the test failed now because it is expecting the broken behaviour and we've fixed it, but it needs to be the other way around

sudiptadas19’s picture

Status: Needs work » Needs review

Test file removed. Updated changes available in MR346. Please review.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Seems to be a simple isset() check. I see the test file was added and then removed so not sure if a new one is needed?

Also may need a reroll for 9.5.x. The MR is aimed at 9.2.x

But following the testing steps

Make sure contact module is installed
Turn maintenance mode on
Went to /user/1 because the code checks $route_name == 'entity.user.canonical'

Not sure how to trigger local tasks but there are no local tasks.

Would say this needs an issue summary update (so move to PNMI)
Or maybe closed as can't reproduce.

andypost’s picture

Btw #34 ist the best test to reproduce (

smustgrave’s picture

Issue tags: -Needs tests +Bug Smash Initiative
StatusFileSize
new1 KB
new1.66 KB

Updated the patch #34. Uploading a tests only patch.

The last submitted patch, 49: 2479449-49-tests-only.patch, failed testing. View results

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/contact/tests/src/Unit/ContactTest.php
    @@ -0,0 +1,36 @@
    +use EasyRdf\Exception;
    

    This is the wrong namespace, I think we just want to use \Exception in the code (ie with the \), however read on below, I think we don't need either.

  2. +++ b/core/modules/contact/tests/src/Unit/ContactTest.php
    @@ -0,0 +1,36 @@
    +  /**
    +   * Modules to enable.
    +   *
    +   * @var array
    +   */
    +  protected static $modules = ['contact'];
    

    I don't think this is supported/required with a UnitTestCase, so we can remove it

  3. +++ b/core/modules/contact/tests/src/Unit/ContactTest.php
    @@ -0,0 +1,36 @@
    +    $route_name = 'entity.user.canonical';
    

    I don't think we need a local variable for the route name, lets just pass it straight to the function

  4. +++ b/core/modules/contact/tests/src/Unit/ContactTest.php
    @@ -0,0 +1,36 @@
    +    try {
    ...
    +    }
    +    catch (Exception $e) {
    +      $this->fail('Exception thrown');
    +    }
    

    PHPUnit will fail if there's an unhandled exception, so we don't need the try catch

  5. +++ b/core/modules/contact/tests/src/Unit/ContactTest.php
    @@ -0,0 +1,36 @@
    +      $this->assertTrue(TRUE, 'No warning thrown');
    

    Instead of this, I think we test the valid use-case (ie when $data['tabs'][0] is set), so then we have a positive assertion that expands coverage of that method rather than testing for just the exception case - thoughts?

pradhumanjain2311’s picture

StatusFileSize
new1.14 KB
new1.41 KB

Try to Addressed Comment #52
Still need to work on Point 5.

smustgrave’s picture

So contact_menu_local_tasks_alter doesn't return anything so how would be best to test?

larowlan’s picture

I assume it alters by reference (on phone didn't check)

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Issue summary: View changes

The next task here is to convert the latest patch to an MR, that is suitable for a first issue.

santhosh@21 made their first commit to this issue’s fork.

mrinalini9 made their first commit to this issue’s fork.

mrinalini9’s picture

Status: Needs work » Needs review

Fixed pipeline issues, please review it.

Thanks!

smustgrave changed the visibility of the branch 2479449-contactmenulocaltasksalter-should-check to hidden.

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Tweaked the test slightly but test-only shows the test coverage and code fix is straight forward.

quietone’s picture

Assigned: Unassigned » quietone

I read the issue, comments and the MR etc. I found all questions answered and all core gates have been addressed. I think this is good to go.

I have updated credit.

Assigning to myself to commit within 24 hours.

  • quietone committed 57ef3662 on 10.3.x
    Issue #2479449 by sudiptadas19, smustgrave, akashkumar07, rithesh bk,...

  • quietone committed 7bf99407 on 10.4.x
    Issue #2479449 by sudiptadas19, smustgrave, akashkumar07, rithesh bk,...

  • quietone committed 0a6b5691 on 11.0.x
    Issue #2479449 by sudiptadas19, smustgrave, akashkumar07, rithesh bk,...

  • quietone committed 833e599d on 11.x
    Issue #2479449 by sudiptadas19, smustgrave, akashkumar07, rithesh bk,...
quietone’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Thanks!

Committed to 11.x, 11.0.x, 10.4.x, and 10.3.x.

quietone’s picture

Assigned: quietone » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.