EclipseGc

_block_get_renderable_region

Feb 7th, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. function _block_get_renderable_region($list = array()) {
  2.   $weight = 0;
  3.   $build = array();
  4.   foreach ($list as $key => $block) {
  5.     $config = $block->getBlock();
  6.     $build[$key] = array(
  7.       '#block' => $block,
  8.       '#weight' => ++$weight,
  9.       '#theme_wrappers' => array('block'),
  10.     );
  11.  
  12.     // Block caching is not compatible with node_access modules. We also
  13.     // preserve the submission of forms in blocks, by fetching from cache
  14.     // only if the request method is 'GET' (or 'HEAD'). User 1 being out of
  15.     // the regular 'roles define permissions' schema, it brings too many
  16.     // chances of having unwanted output get in the cache and later be served
  17.     // to other users. We therefore exclude user 1 from block caching.
  18.     if (
  19.       $GLOBALS['user']->uid == 1 ||
  20.       count(module_implements('node_grants')) ||
  21.       !in_array($_SERVER['REQUEST_METHOD'], array('GET', 'HEAD')) ||
  22.       in_array($config->cache, array(DRUPAL_NO_CACHE, DRUPAL_CACHE_CUSTOM))
  23.     ) {
  24.       // Non-cached blocks get built immediately. Provides more content
  25.       // that can be easily manipulated during hook_page_alter().
  26.       $build[$key] = _block_get_renderable_block($build[$key]);
  27.     }
  28.     else {
  29.       $build[$key] += array(
  30.         '#pre_render' => array('_block_get_renderable_block'),
  31.         '#cache' => array(
  32.           'keys' => array($config->module, $config->delta),
  33.           'granularity' => $config->cache,
  34.           'bin' => 'block',
  35.           'expire' => CACHE_TEMPORARY,
  36.         ),
  37.       );
  38.     }
  39.  
  40.     // Add contextual links for this block; skip the main content block, since
  41.     // contextual links are basically output as tabs/local tasks already. Also
  42.     // skip the help block, since we assume that most users do not need or want
  43.     // to perform contextual actions on the help block, and the links needlessly
  44.     // draw attention on it.
  45.     if ($key != 'system_main' && $key != 'system_help') {
  46.       $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($config->get('module'), $config->get('delta')));
  47.     }
  48.   }
  49.   $build['#sorted'] = TRUE;
  50.   return $build;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment