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

Created on 21 May 2012, about 13 years ago
Updated 27 June 2023, about 2 years 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 3 days 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.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for posting

    As it's been 11 years wonder if this is still a desired feature?

    Thanks!

  • Status changed to Closed: works as designed 2 months ago
  • πŸ‡³πŸ‡ΏNew Zealand quietone

    Nearly another two years and there is no discussion or support for this idea.

    The proposal doesn't met the Criteria for evaluating proposed changes β†’ . In this case, there is not demonstrated demand and support for the change.

    If there is interest in this re-open the issue and add a comment. Or open a new issue and reference this one.

Production build 0.71.5 2024