0

I use block access to determine which block a role can edit. I enabled Access the block administration page and View all blocks permissions so that my blocks_editor role now can access the admin/structure/block page.

But the page displays the complete and huge list of blocks, with a configure link when allowed to do so, as in screen capture below :

enter image description here

How can I filter/restrict this output to the list of blocks the role has permission to edit ?

Or as an alternative, how can I programmatically generate in a block, the links to blocks a role has access to ?

Thank you.

1

Checking the code, this popped up:

  // Remove the block completely if it's not allowed to be viewed
  if (!block_access_can_view($module, $delta)) {
    unset($form['blocks'][$key]);

in block_access_check_perms (.module file)

Otherwise it only removes the operations that user doesn't have access to. Now, this function gets called in the form_alter for the block overview page. So, you have two options as far as I can see.

First, restrict the view permission to be the same as edit (these permissions have no effect on the front-end visibility, as per the project page). This is your best bet I believe.

The other option is to alter the form again after this module has already altered it, run your own checks and then unset the blocks with no operations left.

1

Nick's answer put me on the right way. I suppose there is a more straight way to theme this in a table than with form markup, but this works just fine.

<?php
/**
 * Implements hook_form_FORM_ID_alter();
 */
function MYMODULE_form_block_admin_display_form_alter(&$form, &$form_state, $form_id) {

  global $user;
  if( !in_array('administrator', array_values($user->roles)))  {
    //Prepare new output
    $form['table']= array(
      '#type' => 'markup',
      '#prefix' => '<table>',
      '#suffix' => '</table>',
    );
    $form['table']['header']= array(
      '#type' => 'markup',
      '#markup' => '<thead><th>'.t('Block name').'</th><th>'.t('Operations').'</th></thead>',
    );

    foreach ($form['blocks'] as $key => $value) {
      $module = $form['blocks'][$key]['module']['#value'];
      $delta = $form['blocks'][$key]['delta']['#value'];
      //My custom permissions checks, with block access functions
      if ( block_access_can_config_description($module, $delta) || block_access_can_config_body($module, $delta) ) { 

        $form['table'][$delta] = array(
          '#type' => 'markup',
          '#prefix' => '<tr><td>',
          '#suffix' => '</td>',
          '#markup' => $form['blocks'][$key]['info']['#markup'],
        );
        $form['table'][$delta.'link'] = array(
          '#type' => 'markup',
          '#prefix' => '<td>',
          '#suffix' => '</td></tr>',
          '#markup' => l(t('edit'), $form['blocks'][$key]['configure']['#href']),
        );      
      }
    }
    //I don't need the standard form anymore
    unset($form['blocks']);
    unset($form['block_regions']);
    unset($form['actions']); 
  }
}

This gives following output in the altered admin/structure/block page, depending on the user's permissions and the permissions checks done :

Drupal 7 : how to alter admin/structure/block output

  • is it a custom module or you overwrite the block module? – CocoSkin Jul 18 '15 at 11:35
  • @CocoSkin In a custom module of course :) – Kojo Jul 18 '15 at 11:36
0

I done this once with Block Access. Here is what I did.

  1. Under admin/people/permissions, check "Access the block administration page" and "View all blocks" permissions for who has access to edit blocks. enter image description here
  2. Inside each block edit: set all permission for administrator only, except those specific setting you allow them to change. Like "Role Specific Config_Body Setting", "Role Specific Config_Desc Settings" and "Role Specific Config_title Settings". enter image description here
  • I already did all this, thank you, as explained I believe in my question. My question is how to clean up the block list so that it shows only the blocks the role has permission to edit ? Look at the screen capture : I don't want Facet Api or Features or whatever to be in the list, as the role can't edit it. Thanks again – Kojo Jul 16 '15 at 18:05
  • Cocoskin, I carefully tried your purposed settings again, just in case. But the blocks admin list still displays in a poor UX way, with all the blocks and regions... I ended writing custom code, and posted it, could help sbody – Kojo Jul 17 '15 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.