I had this code in an update hook, since some versions of this database are a little out of sync with others:

  $menus = menu_get_names();
  if (!in_array('secondary-links', $menus)) {
    // There was an update that deleted the secondary-links menu. Put it back. 
    $ret[] = update_sql("INSERT INTO {menu_custom} (menu_name, title, description) VALUES ('secondary-links', 'Secondary links', 'Secondary links are often used for pages like legal notices, contact details, and other secondary navigation items that play a lesser role than primary links')");
  }

However, because the menu_get_names() function checks against the menu_links table instead of the menu_custom table, it will only bring up the name of menus that have links assigned. Secondary links did not, so people were getting errors during the upgrade path since it executed the insert statement regardless.

I'm not sure if this is by design or not, but it's definitely not what I would've expected from a function called menu_get_names(). :)

CommentFileSizeAuthor
#4 784856.patch2.28 KBdmitrig01
#2 784856.patch965 bytesdmitrig01

Comments

dmitrig01’s picture

Assigned: Unassigned » dmitrig01

This does seem somewhat illogical.

dmitrig01’s picture

Status: Active » Needs review
StatusFileSize
new965 bytes

So this is an interesting problem.

Basically, there isn't any way to tell what menus there are except by the menu_name property in the menu_links table. System module defines menu blocks for the default menus, but after that different modules can define their own blocks and menu_names if they want.

However, menu.module does have a menu_custom table. It also has a menu_get_menus function, thus rending menu_get_names useless. It's not used anywhere in core anyway. Should you decide to go this route, the attached patch removes the function altogether.

That being said, I don't know what the right thing is to do. However I think we can remove menu_get_names because it's useless.

Status: Needs review » Needs work

The last submitted patch, 784856.patch, failed testing.

dmitrig01’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.28 KB
cwgordon7’s picture

Status: Needs review » Reviewed & tested by the community

Nice catch, good removal of dead code, and passes tests too, so this is good to go.

sun’s picture

#4: 784856.patch queued for re-testing.

sun’s picture

Issue tags: +API change

I agree it doesn't make sense. However, that's an API change, so it's webchick's call.

sun’s picture

Version: 7.x-dev » 8.x-dev

Although badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).

catch’s picture

Title: menu_get_names() will not return menus with no links assigned » menu_get_names() is dead code, remove it
Category: bug » task
dries’s picture

Version: 8.x-dev » 7.x-dev

Committed to 8.x. Thanks!

I'd be comfortable backporting this to D7, but I'll leave it up to @webchick to consider. Updating the version field.

webchick’s picture

Version: 7.x-dev » 8.x-dev
Status: Reviewed & tested by the community » Fixed

Sorry, I don't think so. You never know what contributed/custom code is using those "dead" functions.

Status: Fixed » Closed (fixed)

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

jhodgdon’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)
Issue tags: +Needs documentation updates

Presumably this is an 8.x API change that needs update doc (but please don't document it now, as we're figuring out the system for API change docs in 8.x now)?

Issue summary:
The menu_get_names() function has been removed.

So... for API change doc, what do we suggest any users of this function should do instead?

catch’s picture

They can use menu_get_menus() I think.

jhodgdon’s picture

Status: Postponed (maintainer needs more info) » Needs work

That looks like a reasonable suggestion.

Proposed API change notification (again, please don't put this anywhere until we figure out what we're doing in d8; changed status to needs work until it's recorded though):

title: menu_get_names() function has been removed
removed in: 8.x-UNSTABLE1
body:
The menu_get_names() function from Drupal 7.x has been removed in Drupal 8.x, because it probably didn't work as you'd expect anyway. If you were using it for something, you can probably use menu_get_menus() instead to accomplish the same task.

Thoughts on this proposed doc?

pillarsdotnet’s picture

Probably ought to update the 7.x docs as we3ll.

jhodgdon’s picture

In what way are you suggesting updating the 7.x docs? I don't believe there was a change committed to 7.x.

pillarsdotnet’s picture

There should be a note in the document header of the menu_get_names() function stating that its use is deprecated in favor of the menu_get_menus() function.

EDIT: For now, I posted a note to the api page.

jhodgdon’s picture

Let's leave the 7.x documentation at that.

jhodgdon’s picture

I think this needs a change notification node made?

pillarsdotnet’s picture

Title: menu_get_names() is dead code, remove it » API change notification for: menu_get_names() is dead code, remove it
Status: Needs work » Active
Issue tags: +Novice

Tagging as per the agreed-upon workflow.

aspilicious’s picture

Title: API change notification for: menu_get_names() is dead code, remove it » Menu_get_names() is dead code, remove it
Status: Active » Fixed
Issue tags: -Novice, -Needs change record
jhodgdon’s picture

What happened to the block that shows the change notices on issues in the right sidebar????? I was just about to mark this "needs work" again and say the change notice doesn't exist...

Filed:
#1358328: Change notice block not showing on issue pages

Status: Fixed » Closed (fixed)
Issue tags: -API change

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