Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.912 diff -u -p -r1.912 common.inc --- includes/common.inc 26 May 2009 09:12:28 -0000 1.912 +++ includes/common.inc 26 May 2009 14:22:03 -0000 @@ -3612,6 +3612,14 @@ function drupal_render(&$elements) { $elements['#theme'] = 'markup'; } + // If there is an edit link associated with this element but the #editable + // property has not been set, use the menu callback to determine whether or + // not it is editable by the current user. + if (isset($elements['#edit']) && !isset($elements['#editable']) && drupal_function_exists('menu_get_item')) { + $item = menu_get_item($elements['#edit']); + $elements['#editable'] = !empty($item['access']); + } + // Make any final changes to the element before it is rendered. This means // that the $element or the children can be altered or corrected before the // element is rendered into the final text. @@ -3865,6 +3873,9 @@ function drupal_common_theme() { 'links' => array( 'arguments' => array('links' => NULL, 'attributes' => array('class' => 'links')), ), + 'edit_link' => array( + 'arguments' => array('link' => NULL, 'element' => NULL), + ), 'image' => array( 'arguments' => array('path' => NULL, 'alt' => '', 'title' => '', 'attributes' => NULL, 'getsize' => TRUE), ), Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.491 diff -u -p -r1.491 theme.inc --- includes/theme.inc 26 May 2009 10:41:06 -0000 1.491 +++ includes/theme.inc 26 May 2009 14:22:07 -0000 @@ -675,16 +675,22 @@ function theme() { } else { // The theme call is a template. - $variables = array( - 'template_files' => array() - ); + $variables = array(); if (!empty($info['arguments'])) { + // Populate the variables with arguments passed to the theme function. + // Note that the first argument may be treated specially by template + // preprocess functions, so it must go into the variables array before + // anything else does. $count = 0; foreach ($info['arguments'] as $name => $default) { $variables[$name] = isset($args[$count]) ? $args[$count] : $default; $count++; } } + // Add an empty array of template files as a default; preprocess functions + // will be able to modify this. We include it last, as per the comment + // above. + $variables += array('template_files' => array()); // default render function and extension. $render_function = 'theme_render_template'; @@ -1256,6 +1262,28 @@ function theme_links($links, $attributes } /** + * Return a themed edit link for an element on a page. + * + * @param $link + * An array representing the edit link to be themed, in the format expected + * by theme_links(); e.g., the array can have keys including 'title', 'href', + * 'html', etc. + * @param $element + * An array representing the editable page element. + * @return + * A themed HTML string representing the edit link. + * + * @see theme_links() + */ +function theme_edit_link($link, $element) { + // Construct a CSS class which associates this edit link with the region on + // the page that it edits. + $class = 'edit-link edit-at-' . str_replace('/', '-', $link['href']); + drupal_add_js('misc/editable.js'); + return theme('links', array($class => $link), array('class' => 'links edit-links')); +} + +/** * Return a themed image. * * @param $path @@ -1801,6 +1829,35 @@ function template_preprocess(&$variables $variables['zebra'] = ($count[$hook] % 2) ? 'odd' : 'even'; $variables['id'] = $count[$hook]++; + // If the first item passed to the theme function is an editable element + // which the current user has access to, populate useful variables for + // constructing edit links and other editable markup. + $element = reset($variables); + $variables['is_editable'] = isset($element['#edit']) && !empty($element['#editable']); + // Do not show edit links when the user is already on the page that is being + // linked to. + $show_edit_links = $variables['is_editable'] && $element['#edit'] != $_GET['q']; + // Add appropriate CSS classes that define this element as editable and + // associate it with its edit link. + $variables['edit_class'] = $variables['is_editable'] ? ' editable-region editable-at-' . str_replace('/', '-', $element['#edit']) : ''; + // Define the default edit link. + $variables['edit_url'] = $show_edit_links ? url($element['#edit']) : ''; + if ($show_edit_links) { + $variables['edit_link_text'] = isset($element['#edit_text']) ? $element['#edit_text'] : t('Edit this'); + $variables['edit_link_info'] = array( + 'title' => $variables['edit_link_text'], + 'href' => $element['#edit'], + // Refer users back to the current page after they have completed their + // edits. + 'query' => drupal_get_destination(), + ); + } + else { + $variables['edit_link_text'] = ''; + $variables['edit_link_info'] = ''; + } + $variables['edit_link'] = $show_edit_links ? theme('edit_link', $variables['edit_link_info'], $element) : ''; + // Tell all templates where they are located. $variables['directory'] = path_to_theme(); Index: misc/editable.js =================================================================== RCS file: misc/editable.js diff -N misc/editable.js --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ misc/editable.js 26 May 2009 14:22:08 -0000 @@ -0,0 +1,27 @@ +// $Id$ +(function ($) { + +/** + * Highlights the editable region when hovering over an edit link. + */ +Drupal.behaviors.highlightEditableRegion = { + attach: function (context) { + var addHighlight = function () { + var matches = $(this).attr('class').match(/edit-at-(\S+)/); + if (matches) { + var class = '.editable-at-' + matches[1]; + $(class).addClass('active-editable-region'); + $(this).addClass('active-editable-link'); + } + }; + + var removeHighlight = function () { + $('.active-editable-region').removeClass('active-editable-region'); + $('.active-editable-link').removeClass('active-editable-link'); + }; + + $('.edit-link').hover(addHighlight, removeHighlight); + } +}; + +})(jQuery); Index: modules/block/block.module =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.module,v retrieving revision 1.336 diff -u -p -r1.336 block.module --- modules/block/block.module 24 May 2009 17:39:30 -0000 1.336 +++ modules/block/block.module 26 May 2009 14:22:10 -0000 @@ -270,6 +270,8 @@ function block_get_blocks_by_region($reg $build[$key] = array( '#theme' => 'block', '#block' => $block, + '#edit' => 'admin/build/block/configure/' . $block->module . '/' . $block->delta, + '#edit_text' => _block_edit_text($block), '#weight' => ++$weight, ); } @@ -279,6 +281,25 @@ function block_get_blocks_by_region($reg } /** + * Return appropriate text for linking to the configuration page of a block. + * + * @param $block + * An object representing the rendered block. + * @return + * The link text. + */ +function _block_edit_text($block) { + if (!empty($block->subject)) { + $block_name = $block->subject; + } + else { + $block_info = module_invoke($block->module, 'block_list'); + $block_name = $block_info[$block->delta]['info']; + } + return t('Edit the "@block_name" block', array('@block_name' => $block_name)); +} + +/** * Update the 'block' DB table with the blocks currently exported by modules. * * @return @@ -764,4 +785,4 @@ function template_preprocess_block(&$var $variables['template_files'][] = 'block-' . $variables['block']->region; $variables['template_files'][] = 'block-' . $variables['block']->module; $variables['template_files'][] = 'block-' . $variables['block']->module . '-' . $variables['block']->delta; -} \ No newline at end of file +} Index: modules/block/block.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.tpl.php,v retrieving revision 1.1 diff -u -p -r1.1 block.tpl.php --- modules/block/block.tpl.php 26 Apr 2009 01:15:04 -0000 1.1 +++ modules/block/block.tpl.php 26 May 2009 14:22:10 -0000 @@ -21,11 +21,22 @@ * - $logged_in: Flags true when the current user is a logged-in member. * - $is_admin: Flags true when the current user is an administrator. * + * Edit variables: + * - $is_editable: TRUE when the block is editable by the current user. + * - $edit_class: Contains CSS classes meant to identify the block as editable; + * may be empty. + * - $edit_link: An already-themed link to the edit page for the block; may be + * empty. + * - $edit_url: The full URL to edit the block; may be empty. + * - $edit_link_text: A caption for the link to edit the block; may be empty. + * - $edit_link_info: An array of information describing the link to edit the + * block; may be empty. + * * @see template_preprocess() * @see template_preprocess_block() */ ?> -
+
subject): ?>

subject ?>

@@ -33,4 +44,8 @@
content ?>
+ + + +
Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1058 diff -u -p -r1.1058 node.module --- modules/node/node.module 26 May 2009 09:13:47 -0000 1.1058 +++ modules/node/node.module 26 May 2009 14:22:17 -0000 @@ -1225,6 +1225,8 @@ function node_build($node, $teaser = FAL $build += array( '#theme' => 'node', '#node' => $node, + '#edit' => 'node/' . $node->nid . '/edit', + '#edit_text' => t('Edit this @type', array('@type' => node_get_types('name', $node))), '#teaser' => $teaser, ); return $build; Index: modules/node/node.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.tpl.php,v retrieving revision 1.11 diff -u -p -r1.11 node.tpl.php --- modules/node/node.tpl.php 28 Apr 2009 19:56:00 -0000 1.11 +++ modules/node/node.tpl.php 26 May 2009 14:22:18 -0000 @@ -32,6 +32,17 @@ * teaser listings. * - $id: Position of the node. Increments each time it's output. * + * Edit variables: + * - $is_editable: TRUE when the node is editable by the current user. + * - $edit_class: Contains CSS classes meant to identify the node as editable; + * may be empty. + * - $edit_link: An already-themed link to the edit page for the node; may be + * empty. + * - $edit_url: The full URL to edit the node; may be empty. + * - $edit_link_text: A caption for the link to edit the node; may be empty. + * - $edit_link_info: An array of information describing the link to edit the + * node; may be empty. + * * Node status variables: * - $teaser: Flag for the teaser state. * - $page: Flag for the full page state. @@ -49,7 +60,7 @@ * @see template_preprocess_node() */ ?> -
+
@@ -73,6 +84,10 @@ + + + + -
\ No newline at end of file +
Index: modules/system/system.css =================================================================== RCS file: /cvs/drupal/drupal/modules/system/system.css,v retrieving revision 1.54 diff -u -p -r1.54 system.css --- modules/system/system.css 11 Apr 2009 22:19:45 -0000 1.54 +++ modules/system/system.css 26 May 2009 14:22:19 -0000 @@ -490,6 +490,17 @@ table.sticky-header { } /* +** Highlighted regions for editable.js +*/ +.active-editable-region { + border: solid red 2px; +} + +.active-editable-link a:hover { + color: red; +} + +/* ** Installation clean URLs */ #clean-url.install { Index: themes/garland/block.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/themes/garland/block.tpl.php,v retrieving revision 1.5 diff -u -p -r1.5 block.tpl.php --- themes/garland/block.tpl.php 18 Feb 2009 14:28:25 -0000 1.5 +++ themes/garland/block.tpl.php 26 May 2009 14:22:19 -0000 @@ -1,11 +1,16 @@ -
+
subject)): ?>

subject ?>

content ?>
+ + + + +
Index: themes/garland/node.tpl.php =================================================================== RCS file: /cvs/drupal/drupal/themes/garland/node.tpl.php,v retrieving revision 1.9 diff -u -p -r1.9 node.tpl.php --- themes/garland/node.tpl.php 18 Feb 2009 14:28:25 -0000 1.9 +++ themes/garland/node.tpl.php 26 May 2009 14:22:19 -0000 @@ -1,7 +1,7 @@ -
+
@@ -28,6 +28,10 @@ + + + +
Index: themes/garland/style.css =================================================================== RCS file: /cvs/drupal/drupal/themes/garland/style.css,v retrieving revision 1.55 diff -u -p -r1.55 style.css --- themes/garland/style.css 12 May 2009 08:31:17 -0000 1.55 +++ themes/garland/style.css 26 May 2009 14:22:21 -0000 @@ -290,6 +290,10 @@ table .form-button, table .form-submit { margin-bottom: 2.5em; } +.edit-link { + font-size: 0.8em; +} + /** * Layout */