forked from howard-university-web-services/howard_paragraphs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
howard_paragraphs.module
71 lines (65 loc) · 1.95 KB
/
howard_paragraphs.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* @file
* Howard paragraphs module file.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\paragraphs\Entity\Paragraph;
/**
* Implements hook_help().
*
* @inheritdoc
*/
function howard_paragraphs_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.howard_paragraphs':
$text = file_get_contents(dirname(__FILE__) . "/README.md");
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . $text . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
/**
* Implements hook_preprocess_paragraph().
*
* @param array $variables
* An associative array containing:
* - elements: An array of elements to display in view mode.
* - paragraph: The paragraph object.
* - view_mode: View mode; e.g., 'full', 'teaser'...
*/
function howard_paragraphs_preprocess_paragraph(&$variables) {
/** @var Paragraph $paragraph */
$paragraph = $variables['paragraph'];
// Get the parent bundle.
$parentBundle = $paragraph->getParentEntity()->bundle();
// Hide/show certain elements based on parent content type.
$showWrapper = true;
if( $parentBundle == 'hc_page') {
$showWrapper = false;
}
$variables['hp_show_wrapper'] = $showWrapper;
};
/**
* Implements hook_theme().
* Provides some basic stripped down templates
*/
function howard_paragraphs_theme($existing, $type, $theme, $path) {
return [
'paragraph__default' => [
'base hook' => 'paragraph',
],
'field__entity_reference_revisions' => [
'base hook' => 'paragraph',
],
];
}