-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezcontent_block.module
46 lines (39 loc) · 1.65 KB
/
ezcontent_block.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/**
* @file
* Used for maintaining content listing component changes.
*/
// Define constants to avoid magic strings.
define('BLOCK_TYPE_CONTENT_LISTING_COMPONENT', 'content_listing_component');
define('VIEW_MODE_FULL', 'full');
/**
* Implements hook_preprocess_block().
*/
function ezcontent_block_preprocess_block(&$variables) {
if (in_array($variables['plugin_id'], [
BLOCK_TYPE_CONTENT_LISTING_COMPONENT,
'inline_block:' . BLOCK_TYPE_CONTENT_LISTING_COMPONENT,
])) {
$routeOptions = \Drupal::routeMatch()->getRouteObject()->getOptions();
$blockContentList = isset($routeOptions['_layout_builder']) || isset($routeOptions['_admin_route'])
? $variables['content']['content']
: $variables['content'];
$block = $blockContentList['#block_content'];
if (isset($blockContentList) && isset($block)) {
$block_type = $block->bundle();
if ($block_type == BLOCK_TYPE_CONTENT_LISTING_COMPONENT) {
$variables['#attached']['library'][] = 'ezcontent_block/ezcontent_listing_css';
$block_view_mode = $blockContentList['#view_mode'];
$helper_block_service = \Drupal::service('ezcontent_block.helper_block');
if ($block_view_mode == VIEW_MODE_FULL) {
$content_list_data = $helper_block_service->getContentListingBlock($block);
if (isset($routeOptions['_layout_builder']) || isset($routeOptions['_admin_route'])) {
$variables['content']['content'] = array_merge($blockContentList, $content_list_data);
} else {
$variables['content'] = array_merge($blockContentList, $content_list_data);
}
}
}
}
}
}