forked from stanford-earth/stanford_news
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstanford_news.module
executable file
·38 lines (34 loc) · 1.23 KB
/
stanford_news.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
<?php
/**
* @file
* File description.
*
* Long description.
*/
use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
/**
* Implements hook_panels_build_alter().
*/
function stanford_news_panels_build_alter(array &$build, PanelsDisplayVariant $panels_display) {
$config = $panels_display->getConfiguration();
switch ($config['storage_id']) {
case 'node:stanford_news:full:default':
$dom = new DOMDocument();
// Disable error reports since <picture> tag throws errors.
// @see https://stackoverflow.com/questions/6090667/php-domdocument-errors-warnings-on-html5-tags
libxml_use_internal_errors(TRUE);
$dom->loadHTML(render($build['hero']));
// If the hero region has a _populated_ h1 tag, we dont want to render
// the h1 in the layout.
$h1_tags = $dom->getElementsByTagName('h1');
if ($h1_tags->length && $h1_tags->item(0)->nodeValue && !empty($build['first'])) {
// Find the node title block and unset it.
foreach ($build['first'] as $uuid => $block) {
if (is_array($block) && isset($block['#plugin_id']) && $block['#plugin_id'] == 'stanford_layouts_node_title') {
unset($build['first'][$uuid]);
}
}
}
break;
}
}