updated core to 7.73
This commit is contained in:
@@ -272,7 +272,7 @@ function block_admin_configure($form, &$form_state, $module, $delta) {
|
||||
$form['settings']['title'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Block title'),
|
||||
'#maxlength' => 64,
|
||||
'#maxlength' => 255,
|
||||
'#description' => $block->module == 'block' ? t('The title of the block as shown to the user.') : t('Override the default title for the block. Use <em>!placeholder</em> to display no title, or leave blank to use the default block title.', array('!placeholder' => '<none>')),
|
||||
'#default_value' => isset($block->title) ? $block->title : '',
|
||||
'#weight' => -19,
|
||||
|
||||
+42
-13
@@ -87,13 +87,13 @@
|
||||
* and any value provided can be modified by a user on the block
|
||||
* configuration screen.
|
||||
* - pages: (optional) See 'visibility' above. A string that contains one or
|
||||
* more page paths separated by '\n', '\r', or '\r\n' when 'visibility' is
|
||||
* set to BLOCK_VISIBILITY_NOTLISTED or BLOCK_VISIBILITY_LISTED, or custom
|
||||
* PHP code when 'visibility' is set to BLOCK_VISIBILITY_PHP. Paths may use
|
||||
* '*' as a wildcard (matching any number of characters); '<front>'
|
||||
* designates the site's front page. For BLOCK_VISIBILITY_PHP, the PHP
|
||||
* code's return value should be TRUE if the block is to be made visible or
|
||||
* FALSE if the block should not be visible.
|
||||
* more page paths separated by "\n", "\r", or "\r\n" when 'visibility' is
|
||||
* set to BLOCK_VISIBILITY_NOTLISTED or BLOCK_VISIBILITY_LISTED (example:
|
||||
* "<front>\nnode/1"), or custom PHP code when 'visibility' is set to
|
||||
* BLOCK_VISIBILITY_PHP. Paths may use '*' as a wildcard (matching any
|
||||
* number of characters); '<front>' designates the site's front page. For
|
||||
* BLOCK_VISIBILITY_PHP, the PHP code's return value should be TRUE if the
|
||||
* block is to be made visible or FALSE if the block should not be visible.
|
||||
*
|
||||
* For a detailed usage example, see block_example.module.
|
||||
*
|
||||
@@ -200,11 +200,13 @@ function hook_block_save($delta = '', $edit = array()) {
|
||||
* within the module, defined in hook_block_info().
|
||||
*
|
||||
* @return
|
||||
* An array containing the following elements:
|
||||
* Either an empty array so the block will not be shown or an array containing
|
||||
* the following elements:
|
||||
* - subject: The default localized title of the block. If the block does not
|
||||
* have a default title, this should be set to NULL.
|
||||
* - content: The content of the block's body. This may be a renderable array
|
||||
* (preferable) or a string containing rendered HTML content.
|
||||
* (preferable) or a string containing rendered HTML content. If the content
|
||||
* is empty the block will not be shown.
|
||||
*
|
||||
* For a detailed usage example, see block_example.module.
|
||||
*
|
||||
@@ -253,8 +255,9 @@ function hook_block_view($delta = '') {
|
||||
* specific block.
|
||||
*
|
||||
* @param $data
|
||||
* An array of data, as returned from the hook_block_view() implementation of
|
||||
* the module that defined the block:
|
||||
* The data as returned from the hook_block_view() implementation of the
|
||||
* module that defined the block. This could be an empty array or NULL value
|
||||
* (if the block is empty) or an array containing:
|
||||
* - subject: The default localized title of the block.
|
||||
* - content: Either a string or a renderable array representing the content
|
||||
* of the block. You should check that the content is an array before trying
|
||||
@@ -287,8 +290,9 @@ function hook_block_view_alter(&$data, $block) {
|
||||
* specific block, rather than implementing hook_block_view_alter().
|
||||
*
|
||||
* @param $data
|
||||
* An array of data, as returned from the hook_block_view() implementation of
|
||||
* the module that defined the block:
|
||||
* The data as returned from the hook_block_view() implementation of the
|
||||
* module that defined the block. This could be an empty array or NULL value
|
||||
* (if the block is empty) or an array containing:
|
||||
* - subject: The localized title of the block.
|
||||
* - content: Either a string or a renderable array representing the content
|
||||
* of the block. You should check that the content is an array before trying
|
||||
@@ -359,6 +363,31 @@ function hook_block_list_alter(&$blocks) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Act on block cache ID (cid) parts before the cid is generated.
|
||||
*
|
||||
* This hook allows you to add, remove or modify the custom keys used to
|
||||
* generate a block cache ID (by default, these keys are set to the block
|
||||
* module and delta). These keys will be combined with the standard ones
|
||||
* provided by drupal_render_cid_parts() to generate the final block cache ID.
|
||||
*
|
||||
* To change the cache granularity used by drupal_render_cid_parts(), this hook
|
||||
* cannot be used; instead, set the 'cache' key in the block's definition in
|
||||
* hook_block_info().
|
||||
*
|
||||
* @params $cid_parts
|
||||
* An array of elements used to build the cid.
|
||||
* @param $block
|
||||
* The block object being acted on.
|
||||
*
|
||||
* @see _block_get_cache_id()
|
||||
*/
|
||||
function hook_block_cid_parts_alter(&$cid_parts, $block) {
|
||||
global $user;
|
||||
// This example shows how to cache a block based on the user's timezone.
|
||||
$cid_parts[] = $user->timezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
||||
|
||||
@@ -6,8 +6,7 @@ core = 7.x
|
||||
files[] = block.test
|
||||
configure = admin/structure/block
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
@@ -79,7 +79,7 @@ function block_schema() {
|
||||
),
|
||||
'title' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => 64,
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Custom title for the block. (Empty string will use block default title, <none> will remove the title, text will cause block to use specified title.)',
|
||||
@@ -472,6 +472,22 @@ function block_update_7008() {
|
||||
db_drop_field('block', 'throttle');
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase {block}.title length to 255 characters.
|
||||
*/
|
||||
function block_update_7009() {
|
||||
db_change_field('block', 'title', 'title',
|
||||
array(
|
||||
'type' => 'varchar',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'description' => 'Custom title for the block. (Empty string will use block default title, <none> will remove the title, text will cause block to use specified title.)',
|
||||
'translatable' => TRUE,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup updates-7.x-extra".
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ Drupal.behaviors.blockSettingsSummary = {
|
||||
$('fieldset#edit-node-type', context).drupalSetSummary(function (context) {
|
||||
var vals = [];
|
||||
$('input[type="checkbox"]:checked', context).each(function () {
|
||||
vals.push($.trim($(this).next('label').text()));
|
||||
vals.push($.trim($(this).next('label').html()));
|
||||
});
|
||||
if (!vals.length) {
|
||||
vals.push(Drupal.t('Not restricted'));
|
||||
@@ -35,7 +35,7 @@ Drupal.behaviors.blockSettingsSummary = {
|
||||
$('fieldset#edit-role', context).drupalSetSummary(function (context) {
|
||||
var vals = [];
|
||||
$('input[type="checkbox"]:checked', context).each(function () {
|
||||
vals.push($.trim($(this).next('label').text()));
|
||||
vals.push($.trim($(this).next('label').html()));
|
||||
});
|
||||
if (!vals.length) {
|
||||
vals.push(Drupal.t('Not restricted'));
|
||||
@@ -49,7 +49,7 @@ Drupal.behaviors.blockSettingsSummary = {
|
||||
return Drupal.t('Not customizable');
|
||||
}
|
||||
else {
|
||||
return $radio.next('label').text();
|
||||
return $radio.next('label').html();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+111
-50
@@ -16,7 +16,7 @@ define('BLOCK_REGION_NONE', -1);
|
||||
define('BLOCK_CUSTOM_FIXED', 0);
|
||||
|
||||
/**
|
||||
* Shows this block by default, but lets individual users hide it.
|
||||
* Shows this block by default, but lets individual users hide it.
|
||||
*/
|
||||
define('BLOCK_CUSTOM_ENABLED', 1);
|
||||
|
||||
@@ -59,6 +59,7 @@ function block_help($path, $arg) {
|
||||
$output .= '<dd>' . t('Users with the <em>Administer blocks</em> permission can <a href="@block-add">add custom blocks</a>, which are then listed on the <a href="@blocks">Blocks administration page</a>. Once created, custom blocks behave just like default and module-generated blocks.', array('@blocks' => url('admin/structure/block'), '@block-add' => url('admin/structure/block/add'))) . '</dd>';
|
||||
$output .= '</dl>';
|
||||
return $output;
|
||||
|
||||
case 'admin/structure/block/add':
|
||||
return '<p>' . t('Use this page to create a new custom block.') . '</p>';
|
||||
}
|
||||
@@ -66,7 +67,7 @@ function block_help($path, $arg) {
|
||||
$demo_theme = !empty($arg[4]) ? $arg[4] : variable_get('theme_default', 'bartik');
|
||||
$themes = list_themes();
|
||||
$output = '<p>' . t('This page provides a drag-and-drop interface for assigning a block to a region, and for controlling the order of blocks within regions. Since not all themes implement the same regions, or display regions in the same way, blocks are positioned on a per-theme basis. Remember that your changes will not be saved until you click the <em>Save blocks</em> button at the bottom of the page. Click the <em>configure</em> link next to each block to configure its specific title and visibility settings.') . '</p>';
|
||||
$output .= '<p>' . l(t('Demonstrate block regions (@theme)', array('@theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '</p>';
|
||||
$output .= '<p>' . l(t('Demonstrate block regions (!theme)', array('!theme' => $themes[$demo_theme]->info['name'])), 'admin/structure/block/demo/' . $demo_theme) . '</p>';
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +144,7 @@ function block_menu() {
|
||||
);
|
||||
foreach (list_themes() as $key => $theme) {
|
||||
$items['admin/structure/block/list/' . $key] = array(
|
||||
'title' => check_plain($theme->info['name']),
|
||||
'title' => $theme->info['name'],
|
||||
'page arguments' => array($key),
|
||||
'type' => $key == $default_theme ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
|
||||
'weight' => $key == $default_theme ? -10 : 0,
|
||||
@@ -162,7 +163,7 @@ function block_menu() {
|
||||
);
|
||||
}
|
||||
$items['admin/structure/block/demo/' . $key] = array(
|
||||
'title' => check_plain($theme->info['name']),
|
||||
'title' => $theme->info['name'],
|
||||
'page callback' => 'block_admin_demo',
|
||||
'page arguments' => array($key),
|
||||
'type' => MENU_CALLBACK,
|
||||
@@ -189,6 +190,7 @@ function _block_themes_access($theme) {
|
||||
* @param $theme
|
||||
* The theme whose blocks are being configured. If not set, the default theme
|
||||
* is assumed.
|
||||
*
|
||||
* @return
|
||||
* The theme that should be used for the block configuration page, or NULL
|
||||
* to indicate that the default theme should be used.
|
||||
@@ -261,7 +263,7 @@ function block_page_build(&$page) {
|
||||
$all_regions = system_region_list($theme);
|
||||
|
||||
$item = menu_get_item();
|
||||
if ($item['path'] != 'admin/structure/block/demo/' . $theme) {
|
||||
if ($item === FALSE || $item['path'] != 'admin/structure/block/demo/' . $theme) {
|
||||
// Load all region content assigned via blocks.
|
||||
foreach (array_keys($all_regions) as $region) {
|
||||
// Assign blocks to region.
|
||||
@@ -281,10 +283,8 @@ function block_page_build(&$page) {
|
||||
}
|
||||
else {
|
||||
// Append region description if we are rendering the regions demo page.
|
||||
$item = menu_get_item();
|
||||
if ($item['path'] == 'admin/structure/block/demo/' . $theme) {
|
||||
$visible_regions = array_keys(system_region_list($theme, REGIONS_VISIBLE));
|
||||
foreach ($visible_regions as $region) {
|
||||
foreach (system_region_list($theme, REGIONS_VISIBLE, FALSE) as $region) {
|
||||
$description = '<div class="block-region">' . $all_regions[$region] . '</div>';
|
||||
$page[$region]['block_description'] = array(
|
||||
'#markup' => $description,
|
||||
@@ -343,14 +343,17 @@ function _block_get_renderable_array($list = array()) {
|
||||
// to perform contextual actions on the help block, and the links needlessly
|
||||
// draw attention on it.
|
||||
if ($key != 'system_main' && $key != 'system_help') {
|
||||
$build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($block->module, $block->delta));
|
||||
$build[$key]['#contextual_links']['block'] = array(
|
||||
'admin/structure/block/manage',
|
||||
array($block->module, $block->delta),
|
||||
);
|
||||
}
|
||||
|
||||
$build[$key] += array(
|
||||
'#block' => $block,
|
||||
'#weight' => ++$weight,
|
||||
);
|
||||
$build[$key]['#theme_wrappers'][] ='block';
|
||||
$build[$key]['#theme_wrappers'][] = 'block';
|
||||
}
|
||||
$build['#sorted'] = TRUE;
|
||||
return $build;
|
||||
@@ -386,59 +389,62 @@ function _block_rehash($theme = NULL) {
|
||||
// Gather the blocks defined by modules.
|
||||
foreach (module_implements('block_info') as $module) {
|
||||
$module_blocks = module_invoke($module, 'block_info');
|
||||
$delta_list = array();
|
||||
foreach ($module_blocks as $delta => $block) {
|
||||
// Compile a condition to retrieve this block from the database.
|
||||
$condition = db_and()
|
||||
->condition('module', $module)
|
||||
->condition('delta', $delta);
|
||||
$or->condition($condition);
|
||||
// Add identifiers.
|
||||
$delta_list[] = $delta;
|
||||
$block['module'] = $module;
|
||||
$block['delta'] = $delta;
|
||||
$block['theme'] = $theme;
|
||||
$block['delta'] = $delta;
|
||||
$block['theme'] = $theme;
|
||||
$current_blocks[$module][$delta] = $block;
|
||||
}
|
||||
if (!empty($delta_list)) {
|
||||
$condition = db_and()->condition('module', $module)->condition('delta', $delta_list);
|
||||
$or->condition($condition);
|
||||
}
|
||||
}
|
||||
// Save the blocks defined in code for alter context.
|
||||
$code_blocks = $current_blocks;
|
||||
$database_blocks = db_select('block', 'b')
|
||||
$database_blocks = db_select('block', 'b', array('fetch' => PDO::FETCH_ASSOC))
|
||||
->fields('b')
|
||||
->condition($or)
|
||||
->condition('theme', $theme)
|
||||
->execute();
|
||||
$original_database_blocks = array();
|
||||
foreach ($database_blocks as $block) {
|
||||
// Preserve info which is not in the database.
|
||||
$block->info = $current_blocks[$block->module][$block->delta]['info'];
|
||||
$module = $block['module'];
|
||||
$delta = $block['delta'];
|
||||
$original_database_blocks[$module][$delta] = $block;
|
||||
// The cache mode can only by set from hook_block_info(), so that has
|
||||
// precedence over the database's value.
|
||||
if (isset($current_blocks[$block->module][$block->delta]['cache'])) {
|
||||
$block->cache = $current_blocks[$block->module][$block->delta]['cache'];
|
||||
if (isset($current_blocks[$module][$delta]['cache'])) {
|
||||
$block['cache'] = $current_blocks[$module][$delta]['cache'];
|
||||
}
|
||||
// Preserve info which is not in the database.
|
||||
$block['info'] = $current_blocks[$module][$delta]['info'];
|
||||
// Blocks stored in the database override the blocks defined in code.
|
||||
$current_blocks[$block->module][$block->delta] = get_object_vars($block);
|
||||
$current_blocks[$module][$delta] = $block;
|
||||
// Preserve this block.
|
||||
$bids[$block->bid] = $block->bid;
|
||||
$bids[$block['bid']] = $block['bid'];
|
||||
}
|
||||
drupal_alter('block_info', $current_blocks, $theme, $code_blocks);
|
||||
foreach ($current_blocks as $module => $module_blocks) {
|
||||
foreach ($module_blocks as $delta => $block) {
|
||||
if (!isset($block['pages'])) {
|
||||
// {block}.pages is type 'text', so it cannot have a
|
||||
// default value, and not null, so we need to provide
|
||||
// value if the module did not.
|
||||
$block['pages'] = '';
|
||||
}
|
||||
// Make sure weight is set.
|
||||
if (!isset($block['weight'])) {
|
||||
$block['weight'] = 0;
|
||||
}
|
||||
// Make sure certain attributes are set.
|
||||
$block += array(
|
||||
'pages' => '',
|
||||
'weight' => 0,
|
||||
'status' => 0,
|
||||
);
|
||||
// Check for active blocks in regions that are not available.
|
||||
if (!empty($block['region']) && $block['region'] != BLOCK_REGION_NONE && !isset($regions[$block['region']]) && $block['status'] == 1) {
|
||||
drupal_set_message(t('The block %info was assigned to the invalid region %region and has been disabled.', array('%info' => $block['info'], '%region' => $block['region'])), 'warning');
|
||||
// Disabled modules are moved into the BLOCK_REGION_NONE later so no
|
||||
// need to move the block to another region.
|
||||
$block['status'] = 0;
|
||||
}
|
||||
// Set region to none if not enabled and make sure status is set.
|
||||
// Set region to none if not enabled.
|
||||
if (empty($block['status'])) {
|
||||
$block['status'] = 0;
|
||||
$block['region'] = BLOCK_REGION_NONE;
|
||||
@@ -456,7 +462,15 @@ function _block_rehash($theme = NULL) {
|
||||
else {
|
||||
$primary_keys = array();
|
||||
}
|
||||
drupal_write_record('block', $block, $primary_keys);
|
||||
// If the block is new or differs from the original database block, save
|
||||
// it. To determine whether there was a change it is enough to examine
|
||||
// the values for the keys in the original database record as that
|
||||
// contained every database field.
|
||||
if (!$primary_keys || array_diff_assoc($original_database_blocks[$module][$delta], $block)) {
|
||||
drupal_write_record('block', $block, $primary_keys);
|
||||
// Make it possible to test this.
|
||||
$block['saved'] = TRUE;
|
||||
}
|
||||
// Add to the list of blocks we return.
|
||||
$blocks[] = $block;
|
||||
}
|
||||
@@ -632,7 +646,8 @@ function block_theme_initialize($theme) {
|
||||
$regions = system_region_list($theme, REGIONS_VISIBLE);
|
||||
$result = db_query("SELECT * FROM {block} WHERE theme = :theme", array(':theme' => $default_theme), array('fetch' => PDO::FETCH_ASSOC));
|
||||
foreach ($result as $block) {
|
||||
// If the region isn't supported by the theme, assign the block to the theme's default region.
|
||||
// If the region isn't supported by the theme, assign the block to the
|
||||
// theme's default region.
|
||||
if ($block['status'] && !isset($regions[$block['region']])) {
|
||||
$block['region'] = system_default_region($theme);
|
||||
}
|
||||
@@ -680,6 +695,9 @@ function block_list($region) {
|
||||
/**
|
||||
* Loads a block object from the database.
|
||||
*
|
||||
* This function returns the first block matching the module and delta
|
||||
* parameters, so it should not be used for theme-specific functionality.
|
||||
*
|
||||
* @param $module
|
||||
* Name of the module that implements the block to load.
|
||||
* @param $delta
|
||||
@@ -797,17 +815,18 @@ function block_block_list_alter(&$blocks) {
|
||||
// with different case. Ex: /Page, /page, /PAGE.
|
||||
$pages = drupal_strtolower($block->pages);
|
||||
if ($block->visibility < BLOCK_VISIBILITY_PHP) {
|
||||
// Convert the Drupal path to lowercase
|
||||
// Convert the Drupal path to lowercase.
|
||||
$path = drupal_strtolower(drupal_get_path_alias($_GET['q']));
|
||||
// Compare the lowercase internal and lowercase path alias (if any).
|
||||
$page_match = drupal_match_path($path, $pages);
|
||||
if ($path != $_GET['q']) {
|
||||
$page_match = $page_match || drupal_match_path($_GET['q'], $pages);
|
||||
}
|
||||
// When $block->visibility has a value of 0 (BLOCK_VISIBILITY_NOTLISTED),
|
||||
// the block is displayed on all pages except those listed in $block->pages.
|
||||
// When set to 1 (BLOCK_VISIBILITY_LISTED), it is displayed only on those
|
||||
// pages listed in $block->pages.
|
||||
// When $block->visibility has a value of 0
|
||||
// (BLOCK_VISIBILITY_NOTLISTED), the block is displayed on all pages
|
||||
// except those listed in $block->pages. When set to 1
|
||||
// (BLOCK_VISIBILITY_LISTED), it is displayed only on those pages
|
||||
// listed in $block->pages.
|
||||
$page_match = !($block->visibility xor $page_match);
|
||||
}
|
||||
elseif (module_exists('php')) {
|
||||
@@ -830,32 +849,71 @@ function block_block_list_alter(&$blocks) {
|
||||
* Render the content and subject for a set of blocks.
|
||||
*
|
||||
* @param $region_blocks
|
||||
* An array of block objects such as returned for one region by _block_load_blocks().
|
||||
* An array of block objects such as returned for one region by
|
||||
* _block_load_blocks().
|
||||
*
|
||||
* @return
|
||||
* An array of visible blocks as expected by drupal_render().
|
||||
*/
|
||||
function _block_render_blocks($region_blocks) {
|
||||
// Block caching is not compatible with node access modules. We also
|
||||
// preserve the submission of forms in blocks, by fetching from cache only
|
||||
$cacheable = TRUE;
|
||||
|
||||
// We preserve the submission of forms in blocks, by fetching from cache only
|
||||
// if the request method is 'GET' (or 'HEAD').
|
||||
$cacheable = !count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
|
||||
$cacheable = FALSE;
|
||||
}
|
||||
// Block caching is not usually compatible with node access modules, so by
|
||||
// default it is disabled when node access modules exist. However, it can be
|
||||
// allowed by using the variable 'block_cache_bypass_node_grants'.
|
||||
elseif (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))) {
|
||||
$cacheable = FALSE;
|
||||
}
|
||||
|
||||
// Proceed to loop over all blocks in order to compute their respective cache
|
||||
// identifiers; this allows us to do one single cache_get_multiple() call
|
||||
// instead of doing one cache_get() call per block.
|
||||
$cached_blocks = array();
|
||||
$cids = array();
|
||||
|
||||
if ($cacheable) {
|
||||
foreach ($region_blocks as $key => $block) {
|
||||
if (!isset($block->content)) {
|
||||
if (($cid = _block_get_cache_id($block))) {
|
||||
$cids[$key] = $cid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cids) {
|
||||
// We cannot pass $cids in directly because cache_get_multiple() will
|
||||
// modify it, and we need to use it later on in this function.
|
||||
$cid_values = array_values($cids);
|
||||
$cached_blocks = cache_get_multiple($cid_values, 'cache_block');
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($region_blocks as $key => $block) {
|
||||
// Render the block content if it has not been created already.
|
||||
if (!isset($block->content)) {
|
||||
// Erase the block from the static array - we'll put it back if it has
|
||||
// content.
|
||||
unset($region_blocks[$key]);
|
||||
// Try fetching the block from cache.
|
||||
if ($cacheable && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
|
||||
$array = $cache->data;
|
||||
|
||||
$cid = empty($cids[$key]) ? NULL : $cids[$key];
|
||||
|
||||
// Try fetching the block from the previously loaded cache entries.
|
||||
if (isset($cached_blocks[$cid])) {
|
||||
$array = $cached_blocks[$cid]->data;
|
||||
}
|
||||
else {
|
||||
$array = module_invoke($block->module, 'block_view', $block->delta);
|
||||
|
||||
// Valid PHP function names cannot contain hyphens.
|
||||
$delta = str_replace('-', '_', $block->delta);
|
||||
// Allow modules to modify the block before it is viewed, via either
|
||||
// hook_block_view_alter() or hook_block_view_MODULE_DELTA_alter().
|
||||
drupal_alter(array('block_view', "block_view_{$block->module}_{$block->delta}"), $array, $block);
|
||||
drupal_alter(array('block_view', "block_view_{$block->module}_{$delta}"), $array, $block);
|
||||
|
||||
if (isset($cid)) {
|
||||
cache_set($cid, $array, 'cache_block', CACHE_TEMPORARY);
|
||||
@@ -900,6 +958,8 @@ function _block_render_blocks($region_blocks) {
|
||||
* Theme and language contexts are automatically differentiated.
|
||||
*
|
||||
* @param $block
|
||||
* The block to get the cache_id from.
|
||||
*
|
||||
* @return
|
||||
* The string used as cache_id for the block.
|
||||
*/
|
||||
@@ -914,6 +974,7 @@ function _block_get_cache_id($block) {
|
||||
// Start with common sub-patterns: block identification, theme, language.
|
||||
$cid_parts[] = $block->module;
|
||||
$cid_parts[] = $block->delta;
|
||||
drupal_alter('block_cid_parts', $cid_parts, $block);
|
||||
$cid_parts = array_merge($cid_parts, drupal_render_cid_parts($block->cache));
|
||||
|
||||
return implode(':', $cid_parts);
|
||||
@@ -1013,7 +1074,7 @@ function block_menu_delete($menu) {
|
||||
* Implements hook_form_FORM_ID_alter().
|
||||
*/
|
||||
function block_form_system_performance_settings_alter(&$form, &$form_state) {
|
||||
$disabled = count(module_implements('node_grants'));
|
||||
$disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants')));
|
||||
$form['caching']['block_cache'] = array(
|
||||
'#type' => 'checkbox',
|
||||
'#title' => t('Cache blocks'),
|
||||
|
||||
+123
-3
@@ -75,7 +75,7 @@ class BlockTestCase extends DrupalWebTestCase {
|
||||
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
|
||||
|
||||
// Check to see if the custom block was created by checking that it's in the database.
|
||||
$this->assertNotNull($bid, 'Custom block found in database');
|
||||
$this->assertTrue($bid, 'Custom block found in database');
|
||||
|
||||
// Check that block_block_view() returns the correct title and content.
|
||||
$data = block_block_view($bid);
|
||||
@@ -193,7 +193,7 @@ class BlockTestCase extends DrupalWebTestCase {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test block visibility when using "pages" restriction but leaving
|
||||
* Test block visibility when using "pages" restriction but leaving
|
||||
* "pages" textarea empty
|
||||
*/
|
||||
function testBlockVisibilityListedEmpty() {
|
||||
@@ -305,7 +305,7 @@ class BlockTestCase extends DrupalWebTestCase {
|
||||
))->fetchField();
|
||||
|
||||
// Check to see if the block was created by checking that it's in the database.
|
||||
$this->assertNotNull($bid, 'Block found in database');
|
||||
$this->assertTrue($bid, 'Block found in database');
|
||||
|
||||
// Check whether the block can be moved to all available regions.
|
||||
foreach ($this->regions as $region) {
|
||||
@@ -752,6 +752,48 @@ class BlockTemplateSuggestionsUnitTest extends DrupalUnitTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests for hook_block_view_MODULE_DELTA_alter().
|
||||
*/
|
||||
class BlockViewModuleDeltaAlterWebTest extends DrupalWebTestCase {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Block view module delta alter',
|
||||
'description' => 'Test the hook_block_view_MODULE_DELTA_alter() hook.',
|
||||
'group' => 'Block',
|
||||
);
|
||||
}
|
||||
|
||||
public function setUp() {
|
||||
parent::setUp(array('block_test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that the alter hook is called, even if the delta contains a hyphen.
|
||||
*/
|
||||
public function testBlockViewModuleDeltaAlter() {
|
||||
$block = new stdClass;
|
||||
$block->module = 'block_test';
|
||||
$block->delta = 'test_underscore';
|
||||
$block->title = '';
|
||||
$render_array = _block_render_blocks(array('region' => $block));
|
||||
$render = array_pop($render_array);
|
||||
$test_underscore = $render->content['#markup'];
|
||||
$this->assertEqual($test_underscore, 'hook_block_view_MODULE_DELTA_alter', 'Found expected altered block content for delta with underscore');
|
||||
|
||||
$block = new stdClass;
|
||||
$block->module = 'block_test';
|
||||
$block->delta = 'test-hyphen';
|
||||
$block->title = '';
|
||||
$render_array = _block_render_blocks(array('region' => $block));
|
||||
$render = array_pop($render_array);
|
||||
$test_hyphen = $render->content['#markup'];
|
||||
$this->assertEqual($test_hyphen, 'hook_block_view_MODULE_DELTA_alter', 'Hyphens (-) in block delta were replaced by underscore (_)');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that hidden regions do not inherit blocks when a theme is enabled.
|
||||
*/
|
||||
@@ -857,3 +899,81 @@ class BlockInvalidRegionTestCase extends DrupalWebTestCase {
|
||||
$this->assertNoRaw($warning_message, 'Disabled block in the invalid region will not trigger the warning.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that block rehashing works correctly.
|
||||
*/
|
||||
class BlockHashTestCase extends DrupalWebTestCase {
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'Block rehash',
|
||||
'description' => 'Checks _block_rehash() functionality.',
|
||||
'group' => 'Block',
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp(array('block'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that block rehashing does not write to the database too often.
|
||||
*/
|
||||
function testBlockRehash() {
|
||||
// No hook_block_info_alter(), no save.
|
||||
$this->doRehash();
|
||||
module_enable(array('block_test'), FALSE);
|
||||
// Save the new blocks, check that the new blocks exist by checking weight.
|
||||
_block_rehash();
|
||||
$this->assertWeight(0);
|
||||
// Now hook_block_info_alter() exists but no blocks are saved on a second
|
||||
// rehash.
|
||||
$this->doRehash();
|
||||
$this->assertWeight(0);
|
||||
// Now hook_block_info_alter() exists and is changing one block which
|
||||
// should be saved.
|
||||
$GLOBALS['conf']['block_test_info_alter'] = 1;
|
||||
$this->doRehash(TRUE);
|
||||
$this->assertWeight(10000);
|
||||
// Now hook_block_info_alter() exists but already changed the block's
|
||||
// weight before, so it should not be saved again.
|
||||
$this->doRehash();
|
||||
$this->assertWeight(10000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a block rehash and checks several related assertions.
|
||||
*
|
||||
* @param $alter_active
|
||||
* Set to TRUE if the block_test module's hook_block_info_alter()
|
||||
* implementation is expected to make a change that results in an existing
|
||||
* block needing to be resaved to the database. Defaults to FALSE.
|
||||
*/
|
||||
function doRehash($alter_active = FALSE) {
|
||||
$saves = 0;
|
||||
foreach (_block_rehash() as $block) {
|
||||
$module = $block['module'];
|
||||
$delta = $block['delta'];
|
||||
if ($alter_active && $module == 'block_test' && $delta == 'test_html_id') {
|
||||
$this->assertFalse(empty($block['saved']), "$module $delta saved");
|
||||
$saves++;
|
||||
}
|
||||
else {
|
||||
$this->assertTrue(empty($block['saved']), "$module $delta not saved");
|
||||
}
|
||||
}
|
||||
$this->assertEqual($alter_active, $saves);
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the block_test module's block has a given weight.
|
||||
*
|
||||
* @param $weight
|
||||
* The expected weight.
|
||||
*/
|
||||
function assertWeight($weight) {
|
||||
$db_weight = db_query('SELECT weight FROM {block} WHERE module = :module AND delta = :delta', array(':module' => 'block_test', ':delta' => 'test_html_id'))->fetchField();
|
||||
// By casting to string the assert fails on FALSE.
|
||||
$this->assertIdentical((string) $db_weight, (string) $weight);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,7 @@ version = VERSION
|
||||
core = 7.x
|
||||
hidden = TRUE
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
@@ -22,6 +22,14 @@ function block_test_block_info() {
|
||||
'cache' => variable_get('block_test_caching', DRUPAL_CACHE_PER_ROLE),
|
||||
);
|
||||
|
||||
$blocks['test_underscore'] = array(
|
||||
'info' => t('Test underscore'),
|
||||
);
|
||||
|
||||
$blocks['test-hyphen'] = array(
|
||||
'info' => t('Test hyphen'),
|
||||
);
|
||||
|
||||
$blocks['test_html_id'] = array(
|
||||
'info' => t('Test block html id'),
|
||||
);
|
||||
@@ -34,3 +42,26 @@ function block_test_block_info() {
|
||||
function block_test_block_view($delta = 0) {
|
||||
return array('content' => variable_get('block_test_content', ''));
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view_MODULE_DELTA_alter().
|
||||
*/
|
||||
function block_test_block_view_block_test_test_underscore_alter(&$data, $block) {
|
||||
$data['content'] = 'hook_block_view_MODULE_DELTA_alter';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_view_MODULE_DELTA_alter().
|
||||
*/
|
||||
function block_test_block_view_block_test_test_hyphen_alter(&$data, $block) {
|
||||
$data['content'] = 'hook_block_view_MODULE_DELTA_alter';
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_block_info_alter().
|
||||
*/
|
||||
function block_test_block_info_alter(&$blocks) {
|
||||
if (variable_get('block_test_info_alter')) {
|
||||
$blocks['block_test']['test_html_id']['weight'] = 10000;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@ regions[footer] = Footer
|
||||
regions[highlighted] = Highlighted
|
||||
regions[help] = Help
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-04-03
|
||||
version = "7.22"
|
||||
; Information added by Drupal.org packaging script on 2020-09-16
|
||||
version = "7.73"
|
||||
project = "drupal"
|
||||
datestamp = "1365027012"
|
||||
|
||||
datestamp = "1600272641"
|
||||
|
||||
Reference in New Issue
Block a user