User login

Put edit block links on blocks for easy use by administrators

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.

Resolution

Searched words: 
Extra trick provide edit links to block and view blocks for admin users

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.