Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / chi-teck / drupal-code-generator / templates / d7 / hook / block_list_alter.twig
1 /**
2  * Implements hook_block_list_alter().
3  */
4 function {{ machine_name }}_block_list_alter(&$blocks) {
5   global $language, $theme_key;
6
7   // This example shows how to achieve language specific visibility setting for
8   // blocks.
9
10   $result = db_query('SELECT module, delta, language FROM {my_table}');
11   $block_languages = array();
12   foreach ($result as $record) {
13     $block_languages[$record->module][$record->delta][$record->language] = TRUE;
14   }
15
16   foreach ($blocks as $key => $block) {
17     // Any module using this alter should inspect the data before changing it,
18     // to ensure it is what they expect.
19     if (!isset($block->theme) || !isset($block->status) || $block->theme != $theme_key || $block->status != 1) {
20       // This block was added by a contrib module, leave it in the list.
21       continue;
22     }
23
24     if (!isset($block_languages[$block->module][$block->delta])) {
25       // No language setting for this block, leave it in the list.
26       continue;
27     }
28
29     if (!isset($block_languages[$block->module][$block->delta][$language->language])) {
30       // This block should not be displayed with the active language, remove
31       // from the list.
32       unset($blocks[$key]);
33     }
34   }
35 }