1 block.module | block_custom_block_load($delta, $langcode = LANGUAGE_NONE) |
Returns information from configuration about a user-created (custom) block.
Parameters
$delta: ID of the block to get information for.
$langcode: The language code for loading the block.
Return value
array: Associative array of information stored in configuration for this block, or FALSE if it doesn't exist Array keys:
- delta: Block ID.
- info: Block description.
- body: Block contents.
- format: Filter ID of the filter format for the body.
File
- core/
modules/ block/ block.module, line 191 - Provides the ability to create reusable custom blocks.
Code
function block_custom_block_load($delta, $langcode = LANGUAGE_NONE) {
// Statically cache each translation to prevent multiple database lookups.
$blocks = &backdrop_static(__FUNCTION__, array());
if (isset($blocks[$delta][$langcode])) {
return $blocks[$delta][$langcode];
}
$block = config_get('block.custom.' . $delta);
if (!$block) {
return FALSE;
}
// Ensure all expected keys are present.
$block += array(
'info' => '',
'title' => '',
'body' => '',
'description' => '',
'default_langcode' => LANGUAGE_NONE,
);
// If a translation is available, load it in to the main values.
if ($langcode !== LANGUAGE_NONE && $langcode !== $block['default_langcode'] && isset($block['translations'])) {
$block['langcode'] = $langcode;
foreach (array('info', 'description', 'title', 'body') as $key) {
if (isset($block['translations'][$langcode][$key])) {
$block[$key] = $block['translations'][$langcode][$key];
}
}
// Remove the translations from this copy to save on load bloat. Only the
// source or non-translated load included all translations.
unset($block['translations']);
}
$blocks[$delta][$langcode] = $block;
return $blocks[$delta][$langcode];
}