-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprojectlibre.theme
109 lines (104 loc) · 3.62 KB
/
projectlibre.theme
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* @file
* Bootstrap sub-theme.
*
* Place your custom PHP code in this file.
*/
/**
* Implements template_theme_suggestions_block_alter
*/
function projectlibre_theme_suggestions_block_alter(array &$suggestions, array $variables) {
$content = $variables['elements']['content'];
if (isset($content['#block_content']) && $content['#block_content'] instanceof \Drupal\block_content\BlockContentInterface) {
array_unshift($suggestions, 'block__' . $content['#block_content']->bundle());
}
}
/**
* Implements hook_preprocess_block()
*/
function projectlibre_preprocess_block(&$variables) {
$content = $variables['elements']['content'];
if (isset($content['#block_content']) && $content['#block_content'] instanceof \Drupal\block_content\BlockContentInterface) {
$bundle_block = $content['#block_content']->bundle();
if ($bundle_block == 'cta') {
$variables['attributes']['class'][] = 'cta';
if (isset($content['field_addition_classes']) && !empty($content['field_addition_classes'])) {
$items = $content['field_addition_classes']['#items']->getValue();
$addition_classes = array();
foreach ($items as $key => $value) {
$addition_classes[] = $value['value'];
}
$variables['attributes']['class'][] = implode(' ', $addition_classes);
}
}
}
if ($variables['elements']['#id'] == 'ctalibrecloud_2') {
$form = \Drupal::formBuilder()->getForm('Drupal\libre_register\Form\RegisterForm');
$form_classes = array_diff($form['#attributes']['class'], array('col-md-8', 'col-sm-7'));
$form_classes[] = 'col-md-6';
$form['#attributes']['class'] = $form_classes;
$variables['content']['form_register_product_cloud'] = $form;
}
if ($variables['plugin_id'] == 'page_title_block') {
$node = \Drupal::routeMatch()->getParameter('node');
$node_types = array(
'blog',
'discussion',
'document',
'event',
'wiki',
);
if (is_object($node)) {
$node_type = $node->getType();
if (in_array($node_type, $node_types)) {
$type = \Drupal\node\Entity\NodeType::load($node_type);
$variables['content']['#title'] = $type->label();
}
}
}
}
/**
* Implements hook_preprocess_comment()
*/
function projectlibre_preprocess_comment(&$variables) {
$comment = $variables['elements']['#comment'];
$variables['created'] = format_date($comment->getCreatedTime(), 'long');
}
/**
* Implements hook_preprocess_node()
*/
function projectlibre_preprocess_node(&$variables) {
$node = $variables['node'];
//Hide field featured content
if (isset($variables['content']['field_featured_content']) && $node->getType() == 'group' && $variables['view_mode'] == 'full') {
$update = $node->access('update');
if (!$update) {
unset($variables['content']['field_featured_content']);
}
}
$variables['date'] = format_date($node->getCreatedTime(), 'long');
$variables['comment_count'] = 0;
if ($node->hasField('comment')) {
$comment = $node->get('comment')->getValue();
$variables['comment_count'] = $comment[0]['comment_count'];
}
}
/**
* Implements hook_preprocess_field().
*/
function projectlibre_preprocess_field(&$variables) {
$element = $variables['element'];
if ($element['#field_type'] == 'comment') {
$total_comments = 0;
$items = $element['#items']->getValue();
if (!empty($items)) {
$total_comments = $items[0]['comment_count'];
}
if ($total_comments >= 2) {
$variables['label'] = t('@total Comments', array('@total' => $total_comments));
}else {
$variables['label'] = t('@total Comment', array('@total' => $total_comments));
}
}
}