-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcomuni_module.module
108 lines (95 loc) · 3.48 KB
/
comuni_module.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
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
<?php
use Drupal\comuni_module\Controller\NodeController;
use Drupal\Core\Form\FormStateInterface;
function comuni_module_entity_form_mode_alter(&$form_mode, \Drupal\Core\Entity\EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'user') {
$form_mode = 'comuni_default';
}
}
/**
* Impelemts hook_entity_presave
*/
function comuni_module_node_presave($node) {
$bundle = $node->bundle();
switch ($bundle) {
case 'documento_pubblico':
NodeController::updateFileExtension($node);
break;
case 'documento_privato':
NodeController::updateFileExtension($node);
break;
}
}
function comuni_module_theme_suggestions_fieldset_alter(array &$suggestions, array $variables, $hook){
if (isset($variables['element']['#webform'])) {
$webformID = str_replace("-", "_", $variables['element']['#webform']);
$suggestions[] = $hook . '__' . $webformID;
}
}
function comuni_module_theme_suggestions_form_element_alter(array &$suggestions, array $variables, $hook){
if (isset($variables['element']['#webform'])) {
$webformID = str_replace("-", "_", $variables['element']['#webform']);
$suggestions[] = $hook . '__' . $webformID;
if (!empty($variables['element']['#type'])) {
$suggestions[] = $hook . '__' . $webformID . '__' . $variables['element']['#type'];
}
}
}
/**
* @param $alias
*
* @return int|string
*/
function getNodeIdByAlias(string $alias) {
$data = NULL;
try {
$query = \Drupal::entityQuery('path_alias');
$query->condition('alias', '/' . $alias, '=');
foreach ($aliasIds as $id) {
$path = PathAlias::load($id)->getPath();
$data = (int) str_replace("/node/", "", $path);
}
} catch (\Exception $e) {
$data = $e->getMessage();
}
return $data;
}
/**
* Implements hook_system_breadcrumb_alter().
*/
function comuni_module_system_breadcrumb_alter(\Drupal\Core\Breadcrumb\Breadcrumb &$breadcrumb, \Drupal\Core\Routing\RouteMatchInterface $route_match, array $context) {
if ($breadcrumb && !\Drupal::service('router.admin_context')->isAdminRoute()) {
$title = \Drupal::service('title_resolver')->getTitle(\Drupal::request(), $route_match->getRouteObject());
if (!empty($title)) {
$breadcrumb->addLink(\Drupal\Core\Link::createFromRoute($title, '<none>'));
}
}
}
function comuni_module_form_alter(&$form, FormStateInterface $form_state, $form_id) {
// Adding custom validation for the welcome page type field.
if ($form_id == 'node_appuntamento_edit_form' || $form_id == 'node_ticket_edit_form' || $form_id == 'node_valutazione_edit_form'){
$form['#disabled'] = array('#type' => 'hidden',
'#title' => t('Row 3. Column 1'),
'#required' => FALSE,
'#default_value' => 0,
'#disabled' => TRUE,
);
}
/* fix issue 45 - titolo e descrizione devono poter essere modificati anche dopo la creazione della pagina.
if ($form_id == 'node_pagina_edit_form' ){
// Do some stuff.
if ( $form['field_componenti']['widget'][0]['#paragraph_type']=='titolo_e_descrizione') {
$form['field_componenti']['widget'][0]['#disabled'] = TRUE;
}
}
*/
}
function comuni_module_preprocess_region(&$variables)
{
$bit_svg = './modules/custom/design-comuni-drupal-theme/comuni_theme/node_modules/bootstrap-italia/dist/svg/sprites.svg';
if(file_exists($bit_svg)){
$variables['bit_svg'] = file_get_contents($bit_svg);
}else{
$variables['bit_svg'] = $bit_svg;
}
}