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:
- 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(). - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | simplify_access_checks-2784555-5.patch | 2.31 KB | jstoller |
Comments
Comment #2
jstollerThe attached patch implements the changes in the issue summary, bumping the modules weight up to 4.
Comment #3
stefan.r commentedLooks OK to me... why 4 though?
Comment #4
jstollerThis 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.
Comment #5
jstollerHere's a minor update to prevent the module from throwing an "undefined index" warning when the menu has been deactivated on a content type.
Comment #7
stefan.r commentedComment #9
stefan.r commentedNeeds an 8.x port
Comment #10
stefan.r commented7.x patch introduced a regression: #2852577: Undefined Index