Problem/Motivation

The return statement is missing in MenuLinkManager::menuNameInUse , in /core/lib/Drupal/Core/Menu/MenuLinkManager.php

  public function menuNameInUse($menu_name) {
    $this->treeStorage->menuNameInUse($menu_name);
  }

The function menuNameInUse in core/lib/Drupal/Core/Menu/MenuTreeStorage.php will always return true

public function menuNameInUse($menu_name) {
    $query = $this->connection->select($this->table, NULL, $this->options);
    $query->addField($this->table, 'mlid');
    $query->condition('menu_name', $menu_name);
    $query->range(0, 1);
    return (bool) $this->safeExecuteSelect($query);
  }

Proposed resolution

The fix would be just adding 'return'

  public function menuNameInUse($menu_name) {
    return $this->treeStorage->menuNameInUse($menu_name);
  }

Remaining tasks

Waiting for review

API changes

core/lib/Drupal/Core/Menu/MenuLinkManager.php method menuNameInUse will return bool.
core/lib/Drupal/Core/Menu/MenuTreeStorage.php method menuNameInUse will return bool.

Data model changes

NA

Release notes snippet

NA

CommentFileSizeAuthor
#52 interdiff-48-52.txt500 bytesphthlaap
#52 2736647-52.patch2.88 KBphthlaap
#51 interdiff-48-51.txt1.01 KBphthlaap
#51 2736647-51.patch2.87 KBphthlaap
#48 interdiff-35-48.txt2.5 KBphthlaap
#48 2736647-48.patch2.32 KBphthlaap
#35 fixMenuNameInUse-2736647-35.patch1.07 KBashrafaaref
#31 fixMenuNameInUse-2736647-31.patch517 bytesashrafaaref
#29 fixMenuNameInUse-2736647-29.patch517 bytesashrafaaref
#27 fixMenuNameInUse-2736647-27.patch0 bytesashrafaaref
#21 2736647-21.patch517 bytesnaveenvalecha
#20 2736647-20.patch7.26 KBnaveenvalecha
#16 2736647-16.patch7.26 KBnaveenvalecha
#14 core-fixMenuNameInUse-14-D8.patch517 bytesashrafaaref
#25 core-fixMenuNameInUse-14-D8.patch517 bytesashrafaaref
#8 missing-return-statement-in-MenuLinkManager-2736647-1.patch517 byteskapil.ropalekar
#6 missing-return-statement-in-MenuLinkManager-2736647.patch413 byteskapil.ropalekar
#3 missing-return-statement-in-MenuLinkManager-2736647.patch413 byteskapil.ropalekar

Issue fork drupal-2736647

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ashrafaaref created an issue. See original summary.

ashrafaaref’s picture

Issue summary: View changes
kapil.ropalekar’s picture

Version: 8.1.1 » 8.1.2
Assigned: Unassigned » kapil.ropalekar
Status: Active » Needs review
FileSize
413 bytes

Created patch file for the same. Please review.

Thanks !

naveenvalecha’s picture

Version: 8.1.2 » 8.1.x-dev
Issue tags: -missing return MenuLinkManager menyNameInUse
dawehner’s picture

Good catch! It would be nice to have some form of test coverage

kapil.ropalekar’s picture

Attaching patch again. Test with drupal 8.1.x-dev

Status: Needs review » Needs work

The last submitted patch, 6: missing-return-statement-in-MenuLinkManager-2736647.patch, failed testing.

kapil.ropalekar’s picture

kapil.ropalekar’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: missing-return-statement-in-MenuLinkManager-2736647-1.patch, failed testing.

kapil.ropalekar’s picture

Status: Needs work » Needs review
kapil.ropalekar’s picture

Assigned: kapil.ropalekar » Unassigned
ashrafaaref’s picture

Assigned: Unassigned » ashrafaaref
ashrafaaref’s picture

Status: Needs review » Needs work

The last submitted patch, 14: core-fixMenuNameInUse-14-D8.patch, failed testing.

naveenvalecha’s picture

naveenvalecha’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Needs work

@naveenvalecha
You are adding quite some stuff, just for putting a return statement in :)

The last submitted patch, 16: 2736647-16.patch, failed testing.

naveenvalecha’s picture

Status: Needs work » Needs review
FileSize
7.26 KB

wrong patch :(

naveenvalecha’s picture

The last submitted patch, 20: 2736647-20.patch, failed testing.

Status: Needs review » Needs work

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

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.

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

ashrafaaref’s picture

Status: Needs work » Reviewed & tested by the community

The last submitted patch, 29: fixMenuNameInUse-2736647-29.patch, failed testing.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 31: fixMenuNameInUse-2736647-31.patch, failed testing.

ashrafaaref’s picture

Status: Needs work » Needs review
FileSize
1.07 KB

adding the return statement showed up another issue in MenuTreeStorage which I had to fix to pass the tests. hope that helps.

dawehner’s picture

Status: Needs review » Needs work
Issue tags: +Need tests

Given this bugfix we certainly needs some tests here ...

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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

DanielVeza’s picture

Assigned: ashrafaaref » Unassigned
Issue tags: +Bug Smash Initiative

Might be playing Devil's advocate here a little, but should we fix this or should we deprecate and remove this? It's not being used by core at the moment and looks like it never would have worked, so isn't this just dead code?

phthlaap’s picture

Status: Needs work » Needs review
FileSize
2.32 KB
2.5 KB

Hello, I've uploaded new patch that includes tests. Please help to review.

phthlaap’s picture

Version: 9.5.x-dev » 11.x-dev
phthlaap’s picture

Status: Needs review » Needs work
phthlaap’s picture

phthlaap’s picture

FileSize
2.88 KB
500 bytes

phthlaap’s picture

Issue summary: View changes

Added merge request
Updated issue summary with the correct template

phthlaap’s picture

Status: Needs work » Needs review
smustgrave’s picture

Ran test-only feature

1) Drupal\KernelTests\Core\Menu\MenuLinkTreeTest::testMenuNameInUseMethod
Failed asserting that null is true.
/builds/issue/drupal-2736647/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
/builds/issue/drupal-2736647/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
/builds/issue/drupal-2736647/core/tests/Drupal/KernelTests/Core/Menu/MenuLinkTreeTest.php:152
/builds/issue/drupal-2736647/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
FAILURES!
Tests: 3, Assertions: 30, Failures: 1.

So removing tests tag.

Left a comment on the MR though.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Going to mark it but do wonder about BC.

poker10’s picture

Status: Reviewed & tested by the community » Needs work
Related issues: +#2999314: the service "menu.tree_storage" bug

I think we should update the title/IS in case we are fixing another issue/function here (see: #2999314: the service "menu.tree_storage" bug).

phthlaap’s picture

Title: missing return statement in MenuLinkManager::menuNameInUse » Add a return statement to MenuLinkManager::menuNameInUse and correct the return value of MenuTreeStorage::menuNameInUse
Issue summary: View changes
phthlaap’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Title has been updated and feedback addressed.

DanielVeza’s picture

Is #47 still valid? If there is still no usages in core and this never worked it feels like we should deprecate and remove it

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

I agree with #47 let's deprecate this and remove it in 11.

phthlaap’s picture

Can someone suggest the steps to remove it?

DanielVeza’s picture

Status: Needs work » Needs review

I've deprecated this method and added a test for the deprecation.

Draft CR here - https://www.drupal.org/node/3415432

DanielVeza’s picture

Status: Needs review » Needs work

PHPstan failure here now actually - Needs further review

DanielVeza changed the visibility of the branch 11.x to hidden.