We have for example three blocks in the first sidebar navigation, search-form and main-menu. But except of those three blocks we have set login-form block to be displayed on the first sidebar too. The difference with the login-form block is that when the admin is logged in the login-form there is on the sidebar but admin has no access to see it. So the block is invisible. The visible ones are navigation, search-form, main-menu and are displayed by this order.

The problem occurs when we click the ‘move down’ contextual link of the last block(in our example main-menu) and then we click the ‘move up’ contextual link of the same block. In this case the block disappears due to the invisible login-form block. I happens the same with the search-form block that now has been the last one(after main-menu has disappeared).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

avlachaki’s picture

Title: Remove block when we click move up link due to invisible blocks in the same region. » Removes block when we click move up link due to invisible blocks in the same region.
avlachaki’s picture

Status: Active » Needs review
FileSize
1.3 KB

The problem here was the query that returns all these blocks that are in the region of the block we want to move. Including the invisible ones.

  $query = db_select('block', 'b1');
  $query->join('block', 'b2', 'b1.theme=b2.theme');
  $query->join('block', 'b3', 'b1.region=b3.region');
  $query->condition('b1.status', '1');
  $query->condition('b2.bid', $bid);
  $query->condition('b3.bid', $bid);
  $query->orderBy('b1.weight');
  $query->orderBy('b1.module');
  $query->fields('b1', array('bid', 'module', 'delta', 'weight'));
  $blocks = $query->execute()->fetchAllAssoc('bid');

Instead of this we made a simple query to get the region of the block and then we used block_list function to get all the blocks of a specific region for the current user only. So we have in an array only the blocks of a region that the current user(admin in our case) can see.

  $query = db_select('block', 'b');
  $query->condition('b.bid', $bid);
  $query->fields('b', array('region'));
  $region = $query->execute()->fetchField();

  $blocks = block_list($region);
Pol’s picture

Status: Needs review » Fixed

Thanks ! Committed and fixed.

xxronis’s picture

Good stuff

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.