Put edit block links on blocks for easy use by administrators

Key words and phrases: 
Extra trick provide edit links to block and view blocks for admin users
Description & Info: 

UPDATE: The Zen Theme does this so, so much better, so we'll be stealing from it as soon as we get the chance.

Provide edit links to block and view blocks for admin users by modifying block template files in your theme.

This is very rudimentary but works for the most common blocks. I'm sure it can be generalized to work for all blocks no matter what module defines them.

Create edit-block.tpl.php

    <?php
       
if (
            ((
$block->module == "block") && (user_access('administer blocks'))) ||
            ((
$block->module == "views") && (user_access('administer views')))
        ):
   
?>


        <div class="administer">
            <a href="<?php print check_url(base_path()) ?>admin/build/block/configure/<?php print $block->module;?>/<?php print $block->delta;?>">Edit this block</a>
        </div>
    <?php endif; ?>

Then include in the various block templates you may have and for which you want edit links. (Do not use include_once, you want it to appear for every block!)

For instance, here's our block.tpl.php:

<div id="block-<?php print $block->module; ?>-<?php print $block->delta; ?>" class="block<?php print " block-$block->module"; ?>">
<?php  include('edit-block.tpl.php'); ?>
  <?php if ($block->subject): ?>
  <div class="title"><?php print $block->subject; ?></div>
  <?php endif; ?>
  <div class="content"><?php print $block->content; ?></div>
</div>

Reference:
http://api.drupal.org/api/function/theme_block/5
http://drupal.org/node/120334
Add an "Edit this Block" link
theme('block', $block) Drupal

A related improvement that would be very nice and should be done as a module is something that could provide a link from the block editing page to any configuration handled by the module that provided the block– mostly, a link back to edit the view for Views blocks.

Post new comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <small> <pre> <strike> <sub> <sup>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.