123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- /**
- * Implements hook_block_view_alter().
- *
- * Convert blocks within the footer region to Bootstrap panels.
- *
- * @param array $build
- * The block view render array to alter.
- *
- * @see dr821m_block_view_alter()
- */
- function _dr821_block_view_alter(array &$build) {
- /** @var \Drupal\block\Entity\Block $blockEntity */
- $blockEntity = $build['#block'];
- $region = $blockEntity->getRegion();
- if ($region !== 'footer') {
- return;
- }
- // Request wrapping the block title and content in appropriate classes.
- $build['#pre_render'][] = '_dr821_prerender_block';
- // Wrap the overall block in panel classes.
- if (!isset($build['#attributes']['class'])) {
- $build['#attributes']['class'] = [];
- }
- $build['#dr821_panelize_title_va'] = TRUE;
- $build['#attributes']['class'] += ['panel', 'panel-default', 'col-xs-6'];
- }
- /**
- * Pre-render function to request wrapping of block parts.
- *
- * @param array $block
- *
- * @return mixed
- */
- function _dr821_prerender_block($block) {
- // Wrap the block body in a panel-body container div.
- if (!empty($block['content'])) {
- $block['content']['#theme_wrappers'] = [
- 'container' => [
- '#attributes' => [
- 'class' => ['panel-body'],
- ],
- ],
- ];
- }
- // Tell the preprocess function to wrap the block title as a panel heading
- $block['#dr821_panelize_title'] = TRUE;
- return $block;
- }
- /**
- * Wrap the block title as a panel heading with title.
- *
- * @param array $elements
- */
- function _dr821_panelize_block_title(&$elements) {
- // Do not just assign prefix/suffix: it would lose contextual information.
- $elements['title_prefix']['#markup'] = '<div class="panel-heading">';
- $elements['title_suffix']['#markup'] = '</div>';
- $elements['title_attributes']['class'][] = 'panel-title';
- }
- /**
- * Implements hook_preprocess_block().
- *
- * Wrap the block title as a panel heading if required.
- */
- function dr821_preprocess_block(&$elements, $hook, $info) {
- if ($elements['elements']['#dr821_panelize_title']) {
- _dr821_panelize_block_title($elements);
- }
- }
|