if you put a menu like:

<?php
  // 1. Establish a requestToken.
  // 2. Direct user to Service Provider.
  $items['linkedin/authenticate'] = array(
    'title' => t('LinkedIn Login'),
    'page callback' => 'linkedin_authentication_page',
    'page arguments' => array(_linkedin_request_token()),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'linkedin.inc',
  );
?>

and your function _linkedin_request_token() is in the linkedin.inc file, it fails because the file is not yet loaded. Actually the file is loaded after built up arguments and access checking, it would make sense to load the file prior to any checking so we can organize well our functions instead of putting everything in the module; Does it ?

CommentFileSizeAuthor
#6 drupal8.menu-router-include-file.6.patch1.04 KBsun

Comments

sylvain lecoy’s picture

This is my work around :

in the same file linkedin.module

<?php
/**
 * Implementation of hook_menu().
 */
function linkedin_menu() {
  $items = array();

  // 1. Establish a requestToken.
  // 2. Direct user to Service Provider.
  $items['linkedin/authenticate'] = array(
    'title' => t('LinkedIn Login'),
    'page callback' => 'linkedin_authentication_page',
    'page arguments' => array(_linkedin_request_token_argument()),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
    'file' => 'linkedin.inc',
  );

  return $items;
}

/**
 * Function wrapper that we can remove later if the bug #929506 is resolved.
 * @see http://drupal.org/node/929506
 * 
 * TODO: Remove when the bug is resolved and commited.
 */
function _linkedin_request_token_argument() {
  module_load_include('inc', 'linkedin');
  return _linkedin_request_token();
}
?>

But then the 'file' => 'linkedin.inc' can be removed. And this can be confusing for other developers.

cyberwolf’s picture

Subscribing.

sylvain lecoy’s picture

Version: 6.x-dev » 7.x-dev

Still the same problem in D7 it seems.

marcingy’s picture

Version: 7.x-dev » 8.x-dev

Bugs are fixed in latest version first

sun’s picture

Title: Menu builder should load the 'file' first then run access callback, page arguments and so... » Menu router does not load the 'file' before attempting to invoke callbacks, and fails to find/register them during building
Assigned: Unassigned » sun
Status: Active » Needs review
Issue tags: +API clean-up, +Needs backport to D7
StatusFileSize
new1.04 KB

The defined file not only has to be loaded before attempting to do any router item processing (so that argument loader functions, access callbacks, etc are actually defined before trying to invoke them).

The router (re)building process also has to be adjusted, since it contains explicit checks for defined _to_arg() and _load() argument callbacks.

This bugged me since like forever, and I just stumbled over the problem again in #951298: Make /batch use proper response objects - for which I'm trying to make system_menu() register everything for Batch API callbacks in includes/batch.inc, but none of that works, since the router does not account for the include file definition at all.

Attached patch fixes the issue.

sun’s picture

Status: Needs review » Needs work

The last submitted patch, drupal8.menu-router-include-file.6.patch, failed testing.

sun’s picture

Version: 8.x-dev » 7.x-dev
Assigned: sun » Unassigned
Issue summary: View changes

This code path no longer exists in D8, since hook_menu() has been removed.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.