Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.1022 diff -u -p -r1.1022 common.inc --- includes/common.inc 16 Oct 2009 13:18:30 -0000 1.1022 +++ includes/common.inc 16 Oct 2009 13:48:53 -0000 @@ -3292,7 +3292,7 @@ function drupal_clear_css_cache() { * @return * The cleaned identifier. */ -function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '[' => '-', ']' => '')) { +function drupal_clean_css_identifier($identifier, $filter = array(' ' => '-', '_' => '-', '/' => '-', '[' => '-', ']' => '')) { // By default, we filter using Drupal's coding standards. $identifier = strtr($identifier, $filter); Index: includes/menu.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/menu.inc,v retrieving revision 1.353 diff -u -p -r1.353 menu.inc --- includes/menu.inc 15 Oct 2009 14:07:26 -0000 1.353 +++ includes/menu.inc 16 Oct 2009 17:03:26 -0000 @@ -1615,7 +1615,7 @@ function menu_local_tasks($level = 0) { ->orderBy('weight') ->orderBy('title') ->execute(); - $map = arg(); + $map = $router_item['original_map']; $children = array(); $tasks = array(); $root_path = $router_item['path']; @@ -1756,6 +1756,82 @@ function menu_local_tasks($level = 0) { } /** + * Retrieve contextual links for a system object based on registered local tasks. + * + * This leverages menu_local_tasks() to retrieve the first layer of registered + * local tasks in the menu system for a given system object. For example, if the + * path "node/123" is passed and considering the following menu router items + * using the 'type' MENU_LOCAL_TASK or MENU_DEFAULT_LOCAL_TASK: + * - node/%node/view (default local task) + * - node/%node/edit + * - node/%node/load + * - node/%node/render + * Then this function will return the 'edit', 'load', and 'render' as contextual + * links. + * menu_local_tasks() will translate the given link path into the corresponding + * menu router item (here: "node/%") and only retrieve and prepare the local + * tasks once during a single page request. + * + * @param $path + * The menu router path of the object to retrieve local tasks for, for example + * "node/123" or "admin/structure/menu/manage/[menu_name]". + * + * @return + * A renderable array containing menu router items that are local tasks for + * the passed in path. + * + * @see system_preprocess() + */ +function menu_context_links($path) { + // @todo This access check really doesn't belong into an API function. But as + // of now, there is no better location to entirely prevent the loading and + // building of contextual links in case they should not be rendered at all. + if (!user_access('view contextual links')) { + return array(); + } + $data = &drupal_static(__FUNCTION__); + $tasks = array(); + + // Get the router item for the given link path. + $router_item = menu_get_item($path); + if (!$router_item || !$router_item['access']) { + return $tasks; + } + $root_path = $router_item['path']; + + if (!isset($data[$root_path])) { + // Get all contextual links that are direct children of the router item and + // not of the type 'view'. + $data[$root_path] = db_select('menu_router', 'm') + ->fields('m') + ->condition('tab_parent', $router_item['tab_root']) + ->condition('tab_type', 'view', '<>') + ->orderBy('weight') + ->orderBy('title') + ->execute() + ->fetchAllAssoc('path', PDO::FETCH_ASSOC); + } + $parent_length = drupal_strlen($root_path); + $map = $router_item['original_map']; + foreach ($data[$root_path] as $item) { + // Extract the actual task path argument string from the path. + $key = drupal_substr($item['path'], $parent_length + 1); + _menu_translate($item, $map, TRUE); + + // Build the contextual link data. + $tasks[$item['path']] = array( + '#link' => $item, + '#link_type' => $key, + ); + } + + // Allow modules to alter local tasks or dynamically append further tasks. + drupal_alter('menu_context_links', $tasks, $router_item, $root_path); + + return $tasks; +} + +/** * Returns the rendered local tasks at the top level. */ function menu_primary_local_tasks() { @@ -2827,6 +2903,10 @@ function _menu_router_build($callbacks) $item['tab_parent'] = ''; $item['tab_root'] = $path; } + // If not specified, assign the default tab type for tabs. + elseif (!isset($item['tab_type'])) { + $item['tab_type'] = 'view'; + } for ($i = $item['_number_parts'] - 1; $i; $i--) { $parent_path = implode('/', array_slice($item['_parts'], 0, $i)); if (isset($menu[$parent_path])) { @@ -2899,6 +2979,7 @@ function _menu_router_build($callbacks) 'theme callback' => '', 'description' => '', 'position' => '', + 'tab_type' => '', 'tab_parent' => '', 'tab_root' => $path, 'path' => $path, @@ -2942,6 +3023,7 @@ function _menu_router_save($menu, $masks 'delivery_callback', 'fit', 'number_parts', + 'tab_type', 'tab_parent', 'tab_root', 'title', @@ -2970,6 +3052,7 @@ function _menu_router_save($menu, $masks 'delivery_callback' => $item['delivery callback'], 'fit' => $item['_fit'], 'number_parts' => $item['_number_parts'], + 'tab_type' => $item['tab_type'], 'tab_parent' => $item['tab_parent'], 'tab_root' => $item['tab_root'], 'title' => $item['title'], Index: misc/attached_links.css =================================================================== RCS file: misc/attached_links.css diff -N misc/attached_links.css --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/attached_links.css 16 Oct 2009 14:53:59 -0000 @@ -0,0 +1,38 @@ +/* $Id$ */ + +/** + * Attached links regions. + */ +.attached-links-region { + outline: none; + position: relative; +} +.attached-links-region-active { + outline: #000 dashed 1px; +} + +/** + * Attached links. + */ +ul.attached-links { + float: right; + font-size: 90%; + margin: 0; + padding: 0; +} +ul.attached-links li { + border-left: 1px solid #ccc; + display: inline; + line-height: 100%; + list-style: none; + margin: 0 0 0 0.3em; + padding: 0 0 0 0.6em; +} +ul.attached-links li.first { + border-left: 0; + margin: 0; + padding: 0; +} +ul.attached-links li a { + text-decoration: none; +} Index: misc/attached_links.js =================================================================== RCS file: misc/attached_links.js diff -N misc/attached_links.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/attached_links.js 16 Oct 2009 17:08:27 -0000 @@ -0,0 +1,33 @@ +// $Id$ +(function ($) { + +Drupal.attachedLinks = Drupal.attachedLinks || {}; + +/** + * Attach outline behavior for regions associated with attached links. + */ +Drupal.behaviors.attachedLinks = { + attach: function (context) { + $('ul.attached-links', context).once('attached-links', function () { + $(this).hover(Drupal.attachedLinks.hover, Drupal.attachedLinks.hoverOut); + }); + } +}; + +/** + * Enables outline for the region an attached link is associated with. + */ +Drupal.attachedLinks.hover = function () { + $(this).addClass('attached-links-link-active') + .closest('.attached-links-region').addClass('attached-links-region-active'); +}; + +/** + * Disables outline for the region an attached link is associated with. + */ +Drupal.attachedLinks.hoverOut = function () { + $(this).removeClass('attached-links-link-active') + .closest('.attached-links-region').removeClass('attached-links-region-active'); +}; + +})(jQuery); Index: modules/block/block.api.php =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.api.php,v retrieving revision 1.8 diff -u -p -r1.8 block.api.php --- modules/block/block.api.php 31 Aug 2009 17:06:08 -0000 1.8 +++ modules/block/block.api.php 16 Oct 2009 15:55:32 -0000 @@ -140,6 +140,7 @@ function hook_block_view($delta = '') { 'content' => mymodule_display_block_exciting(), ); break; + case 'amazing': $block = array( 'subject' => t('Default title of the amazing block'), @@ -151,6 +152,79 @@ function hook_block_view($delta = '') { } /** + * Perform alterations to the content of a block. + * + * This hook allows you to modify any data returned by hook_block_view(). + * + * Note that instead of hook_block_view_alter(), which is called for all + * blocks, you can also use hook_block_view_MODULE_DELTA_alter() to alter a + * specific block. + * + * @param $data + * An array of data, as returned from the hook_block_view() implementation of + * the module that defined the block: + * - subject: The localized title of the block. + * - content: Either a string or a renderable array representing the content + * of the block. You should check that the content is an array before trying + * to modify parts of the renderable structure. + * @param $block + * The block object, as loaded from the database, having the main properties: + * - module: The name of the module that defined the block. + * - delta: The identifier for the block within that module, as defined within + * hook_block_info(). + * + * @see hook_block_view_alter() + * @see hook_block_view() + */ +function hook_block_view_alter(&$data, $block) { + // Remove the contextual links attached to all blocks that provide them. + if (is_array($data['content']) && isset($data['content']['#attached_links'])) { + unset($data['content']['#attached_links']); + } + // Add a theme wrapper function defined by the current module to all blocks + // provided by the "somemodule" module. + if (is_array($data['content']) && $block->module == 'somemodule') { + $data['content']['#theme_wrappers'][] = 'mymodule_special_block'; + } +} + +/** + * Perform alterations to a specific block. + * + * Modules can implement hook_block_view_MODULE_DELTA_alter() to modify a + * specific block, rather than implementing hook_block_view_alter(). + * + * Note that this hook fires before hook_block_view_alter(). Therefore, all + * implementations of hook_block_view_MODULE_DELTA_alter() will run before all + * implementations of hook_block_view_alter(), regardless of the module order. + * + * @param $data + * An array of data, as returned from the hook_block_view() implementation of + * the module that defined the block: + * - subject: The localized title of the block. + * - content: Either a string or a renderable array representing the content + * of the block. You should check that the content is an array before trying + * to modify parts of the renderable structure. + * @param $block + * The block object, as loaded from the database, having the main properties: + * - module: The name of the module that defined the block. + * - delta: The identifier for the block within that module, as defined within + * hook_block_info(). + * + * @see hook_block_view_alter() + * @see hook_block_view() + */ +function hook_block_view_MODULE_DELTA_alter(&$data, $block) { + // This code will only run for a specific block. For example, if MODULE_DELTA + // in the function definition above is set to "mymodule_somedelta", the code + // will only run on the "somedelta" block provided by the "mymodule" module. + + // Change the title of the "somedelta" block provided by the "mymodule" + // module. + $data['subject'] = t('New title of the block'); +} + +/** * Act on blocks prior to rendering. * * This hook allows you to add, remove or modify blocks in the block list. The Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.389 diff -u -p -r1.389 block.module --- modules/block/block.module 14 Oct 2009 02:13:14 -0000 1.389 +++ modules/block/block.module 16 Oct 2009 14:00:43 -0000 @@ -280,6 +280,22 @@ function _block_get_renderable_array($li foreach ($list as $key => $block) { $build[$key] = $block->content; unset($block->content); + + // Attach links for this block; skip this for the system main block. + if ($key != 'system_main') { + // Add local task to configure the block. + // @todo Implement proper path/subject/verb URL pattern for blocks. + $router_item = menu_get_item("admin/structure/block/configure/{$block->module}/{$block->delta}"); + $build[$key]['#attached_links'][][] = array( + '#link_type' => 'configure', + '#link' => array( + 'title' => $router_item['title'], + 'href' => "admin/structure/block/configure/{$block->module}/{$block->delta}", + 'options' => (isset($router_item['localized_options']) ? $router_item['localized_options'] : array()), + ), + ); + } + $build[$key] += array( '#block' => $block, '#weight' => ++$weight, @@ -752,6 +768,12 @@ function _block_render_blocks($region_bl } else { $array = module_invoke($block->module, 'block_view', $block->delta); + + // Allow modules to modify the block before it is viewed, via either + // hook_block_view_MODULE_DELTA_alter() or hook_block_view_alter(). + drupal_alter("block_view_{$block->module}_{$block->delta}", $array, $block); + drupal_alter('block_view', $array, $block); + if (isset($cid)) { cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY); } Index: modules/block/block.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.tpl.php,v retrieving revision 1.4 diff -u -p -r1.4 block.tpl.php --- modules/block/block.tpl.php 11 Sep 2009 06:48:02 -0000 1.4 +++ modules/block/block.tpl.php 16 Oct 2009 06:38:27 -0000 @@ -11,6 +11,7 @@ * - $block->module: Module that generated the block. * - $block->delta: An ID for the block, unique within each module. * - $block->region: The block region embedding the current block. + * - $attached_links (array): An array of links that are attached to the block. * - $classes: String of classes that can be used to style contextually through * CSS. It can be manipulated through the variable $classes_array from * preprocess functions. The default values can be one or more of the following: @@ -36,6 +37,11 @@ */ ?>