Commit 3093c22b authored by Dries's avatar Dries

- Patch #606640 by eojthebrave, sun, catch: don't use menu loaders because...

- Patch #606640 by eojthebrave, sun, catch: don't use menu loaders because menu loaders are executed on every menu system access check. Performance improvement.
parent 161e790e
......@@ -190,6 +190,14 @@
* Flags for use in the "context" attribute of menu router items.
*/
/**
* Internal menu flag: Invisible local task.
*
* This flag may be used for local tasks like "Delete", so custom modules and
* themes can alter the default context and expose the task by altering menu.
*/
define('MENU_CONTEXT_NONE', 0x0000);
/**
* Internal menu flag: Local task should be displayed in page context.
*/
......@@ -1859,6 +1867,7 @@ function menu_contextual_links($module, $parent_path, $args) {
$data[$root_path] = db_select('menu_router', 'm')
->fields('m')
->condition('tab_parent', $router_item['tab_root'])
->condition('context', MENU_CONTEXT_NONE, '<>')
->condition('context', MENU_CONTEXT_PAGE, '<>')
->orderBy('weight')
->orderBy('title')
......
......@@ -176,7 +176,8 @@ function _block_compare($a, $b) {
/**
* Menu callback; displays the block configuration form.
*/
function block_admin_configure($form, &$form_state, $block) {
function block_admin_configure($form, &$form_state, $module, $delta) {
$block = block_load($module, $delta);
$form['module'] = array(
'#type' => 'value',
'#value' => $block->module,
......@@ -426,10 +427,7 @@ function block_admin_configure_submit($form, &$form_state) {
* Menu callback: display the custom block addition form.
*/
function block_add_block_form($form, &$form_state) {
$block = new stdClass;
$block->module = 'block';
$block->delta = NULL;
return block_admin_configure($form, $form_state, $block);
return block_admin_configure($form, $form_state, 'block', NULL);
}
function block_add_block_form_validate($form, &$form_state) {
......@@ -511,7 +509,8 @@ function block_add_block_form_submit($form, &$form_state) {
/**
* Menu callback; confirm deletion of custom blocks.
*/
function block_custom_block_delete($form, &$form_state, $block) {
function block_custom_block_delete($form, &$form_state, $module, $delta) {
$block = block_load($module, $delta);
$custom_block = block_custom_block_get($block->delta);
$form['info'] = array('#type' => 'hidden', '#value' => $custom_block['info'] ? $custom_block['info'] : $custom_block['title']);
$form['bid'] = array('#type' => 'hidden', '#value' => $block->delta);
......
......@@ -88,27 +88,25 @@ function block_menu() {
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/structure/block/manage/%block/%'] = array(
$items['admin/structure/block/manage/%/%'] = array(
'title' => 'Configure block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_admin_configure', 4),
'load arguments' => array(5),
'page arguments' => array('block_admin_configure', 4, 5),
'access arguments' => array('administer blocks'),
'file' => 'block.admin.inc',
);
$items['admin/structure/block/manage/%block/%/configure'] = array(
$items['admin/structure/block/manage/%/%/configure'] = array(
'title' => 'Configure block',
'load arguments' => array(5),
'type' => MENU_DEFAULT_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
);
$items['admin/structure/block/manage/%block/%/delete'] = array(
$items['admin/structure/block/manage/%/%/delete'] = array(
'title' => 'Delete block',
'page callback' => 'drupal_get_form',
'page arguments' => array('block_custom_block_delete', 4),
'load arguments' => array(5),
'page arguments' => array('block_custom_block_delete', 4, 5),
'access arguments' => array('administer blocks'),
'type' => MENU_CALLBACK,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_NONE,
'file' => 'block.admin.inc',
);
$items['admin/structure/block/add'] = array(
......@@ -598,22 +596,20 @@ function block_list($region) {
* @param $module
* Name of the module that implements the block to load.
* @param $delta
* Unique ID of the block within the context of $module.
* Unique ID of the block within the context of $module. Pass NULL to return
* an empty $block object for $module.
*
* @return
* A block object.
*/
function block_load($module, $delta) {
$block = db_query('SELECT * FROM {block} WHERE module = :module AND delta = :delta',
array(
':module' => $module,
':delta' => $delta
))
->fetchObject();
if (isset($delta)) {
$block = db_query('SELECT * FROM {block} WHERE module = :module AND delta = :delta', array(':module' => $module, ':delta' => $delta))->fetchObject();
}
// If the block does not exist in the database yet return a stub block
// object.
if (!$block) {
if (empty($block)) {
$block = new stdClass;
$block->module = $module;
$block->delta = $delta;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment