This repository has been archived by the owner on Oct 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
material_base.theme
executable file
·101 lines (95 loc) · 4.29 KB
/
material_base.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
<?php
/**
* @file
* Functions to support theming in the Material base theme.
*/
use Drupal\Core\Template\Attribute;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_preprocess_HOOK() for HTML document templates.
*
* Adds body classes if certain regions have content.
*/
function material_base_preprocess_html(&$variables) {
// Add information about the number of sidebars.
if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'two-sidebars';
}
elseif (!empty($variables['page']['sidebar_first'])) {
$variables['attributes']['class'][] = 'one-sidebar';
$variables['attributes']['class'][] = 'sidebar-first';
}
elseif (!empty($variables['page']['sidebar_second'])) {
$variables['attributes']['class'][] = 'one-sidebar';
$variables['attributes']['class'][] = 'sidebar-second';
}
else {
$variables['attributes']['class'][] = 'no-sidebars';
}
// Add class for admin-toolbar
if (\Drupal::moduleHandler()->moduleExists('admin_toolbar')) {
$variables['attributes']['class'][] = 'admin-toolbar';
}
}
/**
* Implements hook_form_alter().
*/
function material_base_form_alter(&$form, FormStateInterface $form_state, $form_id) {
switch ($form_id) {
case 'user_login_form':
$form['#attributes']['class'][] = 'card card-form';
$form['links'] = Null;
$form['user_icon']['#markup'] = '<div class="user-icon text-align-center"><i class="material-icons text-disabled">lock</i></div>';
$form['user_icon']['#weight'] = -15;
$form['name']['#title'] = Null;
$form['name']['#attributes']['placeholder'] = t('Login');
$form['name']['#description'] = Null;
$form['pass']['#title'] = Null;
$form['pass']['#attributes']['placeholder'] = t('Password');
$form['pass']['#description'] = Null;
$form['actions']['#attributes']['class'][] = 'card-item card-actions divider-top';
$form['actions']['submit']['#attributes']['class'][] = 'btn-accent';
$form['actions']['request_pass']['#markup'] = '<a class="btn pull-right" href="/user/password">' . t('Reset your password') . '</a>';
break;
case 'user_pass':
$form['#attributes']['class'][] = 'card card-form';
$form['user_icon']['#markup'] = '<div class="user-icon text-align-center"><i class="material-icons text-disabled">vpn_key</i></div>';
$form['user_icon']['#weight'] = -15;
$form['mail']['#weight'] = -10;
$form['name']['#title'] = Null;
$form['name']['#attributes']['placeholder'] = t('Login or E-mail');
$form['actions']['#attributes']['class'][] = 'card-item card-actions divider-top';
$form['actions']['submit']['#attributes']['class'][] = 'btn-accent';
break;
case 'user_register_form':
$form['#attributes']['class'][] = 'card card-form';
$form['user_icon']['#markup'] = '<div class="user-icon text-align-center"><i class="material-icons text-disabled">account_circle</i></div>';
$form['user_icon']['#weight'] = -15;
$form['account']['name']['#title'] = Null;
$form['account']['name']['#attributes']['placeholder'] = t('Login');
$form['account']['mail']['#title'] = Null;
$form['account']['mail']['#attributes']['placeholder'] = t('E-mail');
$form['actions']['#attributes']['class'][] = 'card-item card-actions divider-top';
$form['actions']['submit']['#attributes']['class'][] = 'btn-accent';
break;
case 'search_block_form':
$form['keys']['#attributes']['placeholder'] = t('Search');
$form['keys']['#wrapper_attributes']['class'][] = 'icon-left';
$form['keys']['#wrapper_attributes']['data-icon'] = 'search';
$form['actions']['submit']['#attributes']['class'][] = 'hidden';
break;
}
}
/**
* Implements hook_form_views_exposed_form_alter().
*/
function material_base_form_views_exposed_form_alter(&$form, FormStateInterface $form_state) {
// 'keys' should be changed if id was changed in interface
if (isset($form['keys'])) {
$form['#info']['filter-keys']['label'] = Null;
$form['keys']['#attributes']['placeholder'] = t('Search');
$form['keys']['#wrapper_attributes']['class'][] = 'icon-left';
$form['keys']['#wrapper_attributes']['data-icon'] = 'search';
$form['actions']['submit']['#attributes']['class'][] = 'hidden';
}
}