Last updated August 18, 2009. Created by jbrauer on March 29, 2008.
Edited by ronald_istos, jhodgdon, dvessel, CrashTest_. Log in to edit this page.

This snippet builds on another snippet about "Add an Edit this Block link". Instead of a link this goes further to have the edit link look like the tabs for View, Edit, etc. Here is the code to include in your theme's block.tpl.php file:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?>">
<?php
 
if ($block->module == 'block'):
    if (
user_access('administer blocks')) :?>

    <div id="tabs-wrapper">
      <ul class="tabs primary">
        <li class="active">
          <a class="active" href='<?php print check_url(base_path()) ?>admin/build/block/configure/<?php print $block->module;?>/<?php print $block->delta;?>'>Edit</a>
        </li>
      </ul>
    </div>
    <?php
   
endif;
  endif;
?>

<?php if (!empty($block->subject)): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif;?>
  <div class="content"><?php print $block->content ?></div>
</div>

If the core style sheets are being loaded this should produce an "Edit" tab above each block for users who have "administer blocks" privileges.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Does anyone know how could I apply this to 5.9? I also tried this http://drupal.org/node/120334#comment-623801 and it didn't work either.

Nicolas
-------------------------
http://nic.ipwa.net

Nicolas
-------------------------
http://nic.ipwa.net

I think if you just did in this in 5.x it'll work, I'm pretty sure all the code in here will work in 5.x, but I could be wrong.

<?php
if (user_access('administer blocks')) {
print
l('edit block','admin/build/block/configure/' . $block->module . '/' . $block->delta);
}
?>

Web Developer / Drupal Munkey
Randomlink Interactive Inc.
www.randomlink.net

I suggest some changes so that this validates when more than one block is shown on a page and also an addition to bring the user back to the originating page after editing the block. This is based on the block.tpl.php for the Garland theme:

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?>">
<?php
 
// print out an 'Edit Block' link for users with administer blocks privilege
 
if ($block->module == 'block'):
    if (
user_access('administer blocks')) :?>

    <div class="block-tabs-wrapper">
      <ul class="tabs">
        <li>
          <?php print l('Edit Block','admin/build/block/configure/' . $block->module . '/' . $block->delta.'?'.drupal_get_destination()); ?>
        </li>
      </ul>
    </div>
    <?php
   
endif;
  endif;
?>

<?php if (!empty($block->subject)): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif;?>
  <div class="content"><?php print $block->content ?></div>
</div>

It might also be nice to use jquery and css (like Views 2) to hide the tab until you hover over the block so this doesn't break the layout of a page.

Paul Gregory

--------------------------------
www.accessadvertising.co.uk

---
Paul Gregory | Web Developer at Access
http://www.accessadvertising.co.uk

After trying Paul Gregory's code (posted above), I found that drupal_get_destination() was not working properly. It seems that, when using the l() function to create a link, the destination URL must be passed in the options array (3rd argument). See http://drupal.org/node/201195 and http://api.drupal.org/api/function/l.

Here's my modified code. Please let me know if you find any problems or mistakes:

<div id="block-<?php print $block->module.'-'.$block->delta; ?>" class="clear-block block block-<?php print $block->module; ?>">
<?php
 
if ($block->module == 'block'):
    if (
user_access('administer blocks')):
?>

    <div class="block-tabs-wrapper">
      <ul class="tabs primary">
        <li>
          <?php print l('Edit', 'admin/build/block/configure/'.$block->module.'/'.$block->delta, array('query' => drupal_get_destination())); ?>
        </li>
      </ul>
    </div>
<?php
   
endif;
  endif;
?>

<?php if (!empty($block->subject)): ?>
  <h2><?php print $block->subject; ?></h2>
<?php endif;?>
  <div class="content"><?php print $block->content; ?></div>
</div>

Where do I place the "snippet"?

Do I replace the entire block code? This is what I currently have:

<?php
// $Id: block.tpl.php 7156 2010-04-24 16:48:35Z chris $
?>

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?> <?php print $block_zebra; ?> <?php print $position; ?> <?php print $skinr; ?>">
  <div class="inner">
    <div class="corner-top"><div class="corner-top-right corner"></div><div class="corner-top-left corner"></div></div>
    <?php if (isset($edit_links)): ?>
    <?php print $edit_links; ?>
    <?php endif; ?>
  <div class="inner-wrapper">
      <div class="inner-inner">
        <?php if ($block->subject): ?>
        <div class="block-icon pngfix"></div>
        <h2 class="title block-title"><?php print $block->subject ?></h2>
        <?php endif;?>
        <div class="content clearfix">
          <?php print $block->content ?>
        </div>
      </div><!-- /inner-inner -->
  </div><!-- /inner-wrapper -->
    <div class="corner-bottom"><div class="corner-bottom-right corner"></div><div class="corner-bottom-left corner"></div></div>
  </div><!-- /inner -->
</div><!-- /block -->