Problem/Motivation

Menu Link Weight has a number of access checks in the menu_link_weight_form_node_form_alter() function, posing some problems. Because there's no hook for user_access(), there's no way for other modules to override this access. This also adds complexity, exemplified by the custom access checks needed to work with the Menu Admin Per Menu module.

Consider this use case: I only want to allow users to edit the menu of specific content types and only on the node edit form, so I can't give my users "administer menu" permissions.

Proposed resolution

Implement the following two changes:

  1. Remove all access checks and instead check the values of $form['menu']['#access'] and $form['menu']['link']['parent']['#access'] to determine access. These are already set by appropriate access checks, but can be overridden using hook_form_alter().
  2. Increase the weight of this module in the {system} table. In order to work, a form alter hook would need to execute after the core Menu module, but before Menu Link Weight. This is difficult to achieve when both of those modules have a weight of 0.

Comments

jstoller created an issue. See original summary.

jstoller’s picture

Status: Active » Needs review
StatusFileSize
new2.22 KB

The attached patch implements the changes in the issue summary, bumping the modules weight up to 4.

stefan.r’s picture

Looks OK to me... why 4 though?

jstoller’s picture

StatusFileSize
new2.22 KB

This patch fixes a small spelling error.

The weight needs to be at least 2 and I figured I'd leave a little more room to maneuver in, but 4 was pretty arbitrary. Feel free to change it if you think something else makes sense.

jstoller’s picture

StatusFileSize
new2.31 KB

Here's a minor update to prevent the module from throwing an "undefined index" warning when the menu has been deactivated on a content type.

  • stefan.r committed da05f8c on 7.x-1.x authored by jstoller
    Issue #2784555 by jstoller: Simplify access checks and allow modules to...
stefan.r’s picture

Status: Needs review » Fixed

  • stefan.r committed da05f8c on 8.x-1.x authored by jstoller
    Issue #2784555 by jstoller: Simplify access checks and allow modules to...
stefan.r’s picture

Version: 7.x-1.2 » 8.x-1.x-dev
Status: Fixed » Active

Needs an 8.x port

stefan.r’s picture

7.x patch introduced a regression: #2852577: Undefined Index