-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmarty.module
40 lines (37 loc) · 1.3 KB
/
smarty.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
<?php
/**
* @file
* Primary module hooks for Smarty module.
*/
function smarty_element_info_alter(array &$info) {
// Decrease the default size of textfields.
if (isset($info['address'])) {
$info['address']['#smarty'] = FALSE;
$info['address']['#process'][] = 'smarty_address_process';
}
}
function smarty_address_process($element) {
$settings = \Drupal::config('smarty.settings');
if ((!empty($element['#smarty']) || $settings->get('address_apply_all')) && !empty($element['address_line1'])) {
$element['#attributes']['class'][] = 'smarty-element';
$element['address_line1']['#attributes']['class'][] = 'smarty-autocomplete';
$element['address_line1']['#attached']['library'][] = 'smarty/address';
// $element['address_line1']['#attributes']['data-1p-ignore'] = '';
$element['address_line1']['#attached']['drupalSettings']['smarty'] = [
'key' => $settings->get('key'),
'disable_complete' => $settings->get('disable_complete'),
];
foreach ([
'address_line2',
'address_line3',
'locality',
'administrative_area',
'postal_code',
] as $fieldname) {
if (isset($element[$fieldname])) {
$element[$fieldname]['#attributes']['class'][] = 'smarty-' . str_replace('_', '-', $fieldname);
}
}
}
return $element;
}