function views_block_info in Views (for Drupal 7) 8.3
Same name and namespace in other branches
- 7.3 views.module \views_block_info()
Implement hook_block_info().
File
- ./
views.module, line 702 - Primarily Drupal hooks and global API functions to manipulate views.
Code
function views_block_info() {
// Try to avoid instantiating all the views just to get the blocks info.
views_include('cache');
$cache = views_cache_get('views_block_items', TRUE);
if ($cache && is_array($cache->data)) {
return $cache->data;
}
$items = array();
$views = views_get_all_views();
foreach ($views as $view) {
// disabled views get nothing.
if (!$view
->isEnabled()) {
continue;
}
$view
->initDisplay();
foreach ($view
->getExecutable()->displayHandlers as $display) {
if (isset($display) && !empty($display->definition['uses_hook_block'])) {
$result = $display
->executeHookBlockList();
if (is_array($result)) {
$items = array_merge($items, $result);
}
}
if (isset($display) && $display
->getOption('exposed_block')) {
$result = $display
->getSpecialBlocks();
if (is_array($result)) {
$items = array_merge($items, $result);
}
}
}
}
// block.module has a delta length limit of 32, but our deltas can
// unfortunately be longer because view names can be 32 and display IDs
// can also be 32. So for very long deltas, change to md5 hashes.
$hashes = array();
// get the keys because we're modifying the array and we don't want to
// confuse PHP too much.
$keys = array_keys($items);
foreach ($keys as $delta) {
if (strlen($delta) >= 32) {
$hash = md5($delta);
$hashes[$hash] = $delta;
$items[$hash] = $items[$delta];
unset($items[$delta]);
}
}
// Only save hashes if they have changed.
$old_hashes = variable_get('views_block_hashes', array());
if ($hashes != $old_hashes) {
variable_set('views_block_hashes', $hashes);
}
views_cache_set('views_block_items', $items, TRUE);
return $items;
}