|
|
|
@@ -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.
|
|
|
|
@@ -283,8 +285,7 @@ function block_page_build(&$page) {
|
|
|
|
|
// 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 +344,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,18 +390,20 @@ 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;
|
|
|
|
@@ -426,23 +432,20 @@ function _block_rehash($theme = NULL) {
|
|
|
|
|
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;
|
|
|
|
@@ -644,7 +647,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);
|
|
|
|
|
}
|
|
|
|
@@ -692,6 +696,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
|
|
|
|
@@ -809,17 +816,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')) {
|
|
|
|
@@ -842,7 +850,8 @@ 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().
|
|
|
|
@@ -950,6 +959,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.
|
|
|
|
|
*/
|
|
|
|
@@ -964,6 +975,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);
|
|
|
|
|