Remove redundant access check in preprocess_menu hook

Created on 23 December 2022, over 1 year ago
Updated 19 January 2023, over 1 year ago

Problem/Motivation

The implementation of preprocess_menu in the social_course module is unnecessary and can be removed. Additionally it can be quite slow.

The function goes through all menu links and checks if the url is accessible by the current user. This is already done using the access layer in Drupal, and should also never be done in a preprocess function.

I tested this function to see if it actually removed any links and the result was 0. For authenticated users, on a production site with many links, it processed 89 links and removed 0. For a site manager it processed 433 links and removed 0.

Steps to reproduce

Clear your caches, open a page with different roles and dump the result of the if statement in the code below.

if (!$item['url']->access($account)) {
  // Dump result here.
  continue;
}
else {
  $accessible_items[$key] = $item;
}

Proposed resolution

Just get rid of it, it is meaningless and only adds processing time.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ“Œ Task
Status

Fixed

Version

5.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands bramtenhove

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024