-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsoda.theme
98 lines (86 loc) · 3.28 KB
/
soda.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
<?php
/**
* @file
* Theme specific functionality.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\biko_media_src\MediaSrc;
use Drupal\media\Entity\Media;
/**
* Implements hook_preprocess_html().
*/
function soda_preprocess_html(&$variables) {
$path = \Drupal::service('path.current')->getPath();
$alias = trim(\Drupal::service('path.alias_manager')
->getAliasByPath($path), '/');
// Body classes for sidebars.
if (isset($variables['page']['sidebar_first']) && isset($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('body-sidebars-both');
}
elseif (isset($variables['page']['sidebar_first'])) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('body-sidebars-first');
}
elseif (isset($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('body-sidebars-second');
}
else {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('body-sidebars-none');
}
// Alias path class.
$alias_class = preg_replace("/\//", '-', $alias);
if (!empty($alias_class) && strpos($alias_class, 'node') !== 0) {
$variables['attributes']['class'][] = Html::cleanCssIdentifier('alias--' . $alias_class);
}
// If is homepage.
$variables['attributes']['class'][] = \Drupal::service('path.matcher')
->isFrontPage() ? 'frontpage' : '';
// Node type class.
$variables['attributes']['class'][] = isset($variables['node_type']) ? 'nodetype--' . $variables['node_type'] : '';
// Logged in class.
$variables['attributes']['class'][] = $variables['logged_in'] ? 'logged-in' : 'logged-out';
}
/**
* Implements hook_preprocess_page().
*/
function soda_preprocess_page(&$variables) {
$site_config = \Drupal::config('system.site');
$variables['site_name'] = $site_config->get('name');
$variables['site_slogan'] = $site_config->get('slogan');
$variables['site_logo'] = file_url_transform_relative(file_create_url(theme_get_setting('logo.url')));
}
/**
* Implements template_preprocess_block().
*/
function soda_preprocess_block(&$variables) {
}
/**
* Implements hook_preprocess_node().
*/
function soda_preprocess_node(&$variables) {
//EXAMPLE: preprocess a view
/*$result= views_get_view_result('ultimas_paginas', 'default');
if (!empty($result)) {
foreach ($result as $row) {
$title=$row->_entity->getTitle();
$url=$row->_entity->toUrl()->toString();
$item=['label'=>$title, 'url'=>$url];
$variables['ultimas_paginas'][] = $item;
}
}*/
//EXAMPLE: preprocess images
/*$node=$variables['elements']['#node'];
if($node->getType()=='page'){
$image_entity= Media::load($node->field_multimedia->first()->target_id);
$variables['image']['src'] = MediaSrc::getSrc($image_entity, 'large');
$variables['image']['alt'] = MediaSrc::getAlt($image_entity);
}*/
}
//EXAMPLE: preprocess a paragraph
/*function soda_preprocess_paragraph__paragraph_componente_doble(&$variables){
$paragraph = $variables['paragraph'];
$variables['titular']['label']=$paragraph-> field_paragraph_tit_pri_nivel->value;
$variables['boton']['label']=$paragraph-> field_paragraph_boton_url->title;
$variables['boton']['url']=$paragraph-> field_paragraph_boton_url->uri;
}*/