Support closures in menu item arguments (page, access, etc)

Created on 21 May 2012, over 12 years ago
Updated 27 June 2023, about 1 year ago

It'd be awesome if you could do something like this in menu definitions:

$items['thing/new'] = array(
  'title' => 'New thing',
  'page callback' => 'my_thing_form',
  'page arguments' => array(function() { return new MyThing; }),
);

$items['thing/%mything'] = array(
  'title' => 'New thing',
  'page callback' => 'my_thing_form',
  'page arguments' => array(2),
);

And in turn the menu system could check to see if a given argument is callable and if so, call it when preparing the args. We already special case some things passed to arguments, i.e. integers correspond to parts of a path if load functions are defined.

But alas, closures can't be serialized :(

Or can they?

I know this is a pretty crazy request, but I think it would really make module coding alot cleaner by allowing closures in more places where we currently would have to rely on a separate procedural function for a simple 1 liner, and then in turn reference the name of that function in a string.

Any thoughts?

✨ Feature request
Status

Postponed: needs info

Version

9.5

Component
Menu systemΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States mikey_p Dayton, OH

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.71.5 2024