-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotic.theme
411 lines (370 loc) · 15.7 KB
/
robotic.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
<?php
/**
* @file
* Robotic theme.
*
* Place your custom PHP code in this file.
*/
use Drupal\Component\Utility\Html;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
/**
* Implements hook_preprocess_HOOK() for block templates.
*/
function robotic_preprocess_block(&$variables)
{
switch ($variables['base_plugin_id']) {
case 'system_branding_block':
$variables['site_logo'] = '';
if ($variables['content']['site_logo']['#access'] && $variables['content']['site_logo']['#uri']) {
$variables['site_logo'] = str_replace('.svg', '.png', $variables['content']['site_logo']['#uri']);
}
break;
}
switch ($variables['base_plugin_id']) {
case 'system_powered_by_block':
//echo "<pre>";
$variables['content']['#markup'] = 'Designed by <a href="http://www.roboticwave.com">Robotic Wave</a> & Powered by <a href="https://www.drupal.org">Drupal</a>';
break;
}
}
/**
* Preprocess variables for html templates.
* @param $variables
*/
function robotic_preprocess_html(&$variables)
{
$node = \Drupal::request()->attributes->get('node');
if (isset($node->id)) {
$variables['path_info']['args'] = 'node-' . $node->id();
}
}
function robotic_system_powered_by()
{
return '<span>' . t('Powered by <a href="@poweredby">Drupal</a>', array('@poweredby' => 'https://www.drupal.org')) . '</span>';
}
define('SOCIAL_ICON_COUNT', 8);
/**
* Implements hook_preprocess_HOOK().
*/
function robotic_preprocess_page(&$variables)
{
if ($variables['is_front']) {
if (theme_get_setting('is_slideshow', 'robotic') == 1) {
$variables['is_slideshow'] = 1;
$variables['slider_number'] = robotic_get_slider_indicator();
$variables['slider_content'] = robotic_get_slider_content();
}
}
$variables['social_links'] = robotic_get_social_links();
$variables['robotic_colors']['body_bg'] = theme_get_setting('body_bg', 'robotic');
$variables['robotic_colors']['header_bg'] = theme_get_setting('color_bg', 'robotic');
$variables['robotic_colors']['header_font'] = theme_get_setting('color_font', 'robotic');
/*if ($variables['robotic_general']['is_map'] == 1) {
}*/
$variables['robotic_general']['is_map'] = theme_get_setting('is_map', 'robotic');
// Robotic Class
/*if (!empty($variables['page']['sidebar_first']) && !empty($variables['page']['sidebar_second'])) {
$content_class = 'col-md-6';
$sidebar_class = 'col-md-3';
}*/
}
function robotic_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id)
{
if ($form_id == 'search_block_form') {
$form['#attributes']['class'][] = 'searchForm';
$form['keys']['#attributes']['placeholder'] = t('Search');
$form['actions']['submit']['#value'] = html_entity_decode('');
$form['actions']['submit']['#attributes']['class'][] = 'search-button fa';
}
}
function robotic_preprocess_breadcrumb(&$variables)
{
if (($node = \Drupal::routeMatch()->getParameter('node')) && $variables['breadcrumb']) {
$variables['breadcrumb'][] = array(
'text' => $node->getTitle(),
'url' => $node->URL(),
);
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function robotic_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
$form['robotic'] = array(
'#type' => 'vertical_tabs',
'#default_tab' => 'edit-publication',
'#prefix' => '<h2>' . t('Robotic Theme Settings') . '</h2>',
'#weight' => 5,
);
$form['robotic_general'] = array(
'#type' => 'details',
'#title' => t('General'),
'#group' => 'robotic',
);
//Contact Page Google Map API settings start
$form['robotic_general']['gmapapi'] = array(
'#type' => 'fieldset',
'#title' => t('Contact Page | Google Map'),
/*'#group' => 'robotic',*/
'#collapsible' => true,
'#collapsed' => false,
);
$form['robotic_general']['gmapapi']['is_map'] = array(
'#type' => 'checkbox',
'#title' => t('Show Google Map in Contact Page'),
'#default_value' => theme_get_setting('is_map', 'robotic'),
'#description' => t("Check this option to show Google Map in contact page. Uncheck to hide."),
);
$form['robotic_general']['gmapapi']['gmapapi_key'] = array(
'#type' => 'textfield',
'#title' => t('Google Map API Key'),
'#default_value' => theme_get_setting('gmapapi_key', 'robotic'),
'#description' => t("Put your google map api key here."),
);
// Body Color settings start
$form['robotic_general']['color'] = array(
'#type' => 'fieldset',
'#title' => t('Background Color'),
/*'#group' => 'robotic_settings',*/
'#collapsible' => true,
'#collapsed' => false,
);
$form['robotic_general']['color']['body_bg'] = array(
'#type' => 'color',
'#title' => t('Body Background Color'),
'#default_value' => theme_get_setting('body_bg', 'robotic'),
);
// Header Colors start
$form['robotic_general']['color_header'] = array(
'#type' => 'fieldset',
'#title' => t('Header Background & Fonts Color'),
);
$form['robotic_general']['color_header']['color_bg'] = array(
'#type' => 'color',
'#title' => t('Header Background Color'),
'#default_value' => theme_get_setting('color_bg', 'robotic'),
);
$form['robotic_general']['color_header']['color_font'] = array(
'#type' => 'color',
'#title' => t('Header/Menu Fonts Color'),
'#default_value' => theme_get_setting('color_font', 'robotic'),
);
// Sideshow start
$form['robotic_slideshow'] = array(
'#type' => 'details',
'#title' => t('Front Page Slideshow'),
'#group' => 'robotic',
'#collapsible' => true,
'#collapsed' => false,
);
$form['robotic_slideshow']['is_slideshow'] = array(
'#type' => 'checkbox',
'#title' => t('Show Slideshow'),
'#default_value' => theme_get_setting('is_slideshow', 'robotic'),
'#description' => t("Check this option to show Slideshow in front page. Uncheck to hide."),
);
$form['robotic_slideshow']['slide_number'] = array(
'#type' => 'number',
'#title' => t('Number of Slideshow'),
'#default_value' => theme_get_setting('slide_number', 'robotic'),
'#description' => t("How many Slideshow you want...?"),
);
$form['robotic_slideshow']['slide'] = array(
'#markup' => t('You can change the description and URL and image of each slide in the following Slide Setting fieldsets.'),
);
for ($i = 1; $i <= theme_get_setting('slide_number', 'robotic'); $i++) {
$form['robotic_slideshow']['slide' . $i] = array(
'#type' => 'details',
'#title' => t('Slide ' . $i),
'#collapsible' => true,
'#collapsed' => true,
);
$form['robotic_slideshow']['slide' . $i]['slide_title_' . $i] = array(
'#type' => 'textfield',
'#title' => t('Slide ' . $i . ' Title'),
'#default_value' => theme_get_setting('slide_title_' . $i, 'robotic'),
//'#required' => 'required',
);
$form['robotic_slideshow']['slide' . $i]['slide_description_' . $i] = array(
'#type' => 'textarea',
'#title' => t('Slide ' . $i . ' Description'),
'#default_value' => theme_get_setting('slide_description_' . $i, 'robotic'),
);
$form['robotic_slideshow']['slide' . $i]['slide_url_' . $i] = array(
'#type' => 'textfield',
'#title' => t('Slide ' . $i . ' URL'),
'#default_value' => theme_get_setting('slide_url_' . $i, 'robotic'),
);
$form['robotic_slideshow']['slide' . $i]['slide_color_' . $i] = array(
'#type' => 'color',
'#title' => t('Slide ' . $i . ' Background Color'),
'#default_value' => theme_get_setting('slide_color_' . $i, 'robotic'),
);
/*$form['robotic_slideshow']['slide' . $i]['slide_bg_path_' . $i] = array(
'#type' => 'managed_file',
'#title' => t('Slide ' . $i . ' Background Image'),
'#default_value' => theme_get_setting('slide_bg_path_' . $i, 'robotic'),
'#upload_location' => 'public://'
);*/
$form['robotic_slideshow']['slide' . $i]['slide_image_path' . $i] = array(
'#type' => 'managed_file',
'#title' => t('Slide ' . $i . ' Image'),
'#default_value' => theme_get_setting('slide_image_path' . $i, 'robotic'),
'#upload_location' => 'public://',
);
}
//Social Icons settings start
$form['robotic_socialicon'] = array(
'#type' => 'details',
'#title' => t('Social Icons Configuration'),
'#group' => 'robotic',
'#collapsible' => true,
'#collapsed' => true,
);
for ($i = 1; $i <= SOCIAL_ICON_COUNT; $i++) {
$form['robotic_socialicon'][$i] = array(
'#type' => 'details',
// '#type' => 'fieldset',
// '#tree' => TRUE,
'#title' => t("Social icon - {$i}"),
'#collapsible' => true,
'#collapsed' => false,
);
$form['robotic_socialicon'][$i]["social_class_{$i}"] = array(
'#type' => 'textfield',
'#title' => t('Class'),
'#description' => t('Enter <a href="https://fortawesome.github.io/Font-Awesome/icons/#brand" target="_blank">font awesome social icon</a> class. for example "fa-facebook" for facebook'),
'#default_value' => theme_get_setting("social_class_{$i}"),
);
$form['robotic_socialicon'][$i]["social_links_{$i}"] = array(
'#type' => 'textfield',
'#title' => t('Url'),
'#description' => t("Enter your's social sites profile link (url)."),
'#default_value' => theme_get_setting("social_links_{$i}"),
);
}
//help
$form['help'] = array(
'#type' => 'details',
'#title' => t('Need help?'),
'#group' => 'robotic',
);
$form['help']['info'] = array(
'#type' => 'fieldset',
'#title' => t('Thanks for using Robotic Theme!'),
'#description' => t('<h6>Free Support for Questions and Issues, Please Do Not Hesitate to <a href="mailto:[email protected]?Subject=General%20inquiry" target="_top">Contact.</a> </h6><hr>
<h6>Customization Service Available, Please Do Not Hesitate to <a href="mailto:[email protected]?Subject=Customization%20Service" target="_top">Contact.</a> </h6>
'),
);
// Custom submit to save the file permenant.
$form['#submit'][] = 'robotic_settings_form_submit';
}
/**
* Custom submit handler for robotic settings form.
*/
function robotic_settings_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
$account = \Drupal::currentUser();
$values = $form_state->getValues();
for ($i = 0; $i < 6; $i++) {
if (isset($values['slide_image_path' . $i]) && !empty($values['slide_image_path' . $i])) {
// Load the file via file.fid.
$file = file_load($values['slide_image_path' . $i][0]);
// Change status to permanent.
$file->setPermanent();
$file->save();
$file_usage = \Drupal::service('file.usage');
$file_usage->add($file, 'user', 'user', $account->id());
}
//for gb image
/*if (isset($values['slide_bg_path_' . $i]) && !empty($values['slide_bg_path_' . $i])) {
// Load the file via file.fid.
$file = file_load($values['slide_bg_path_' . $i][0]);
// Change status to permanent.
$file->setPermanent();
$file->save();
$file_usage = \Drupal::service('file.usage');
$file_usage->add($file, 'user', 'user', $account->id());
}*/
}
}
/**
* slider content callback
*/
function robotic_get_slider_content()
{
$slider_content = array();
for ($i = 1; $i <= theme_get_setting('slide_number', 'robotic'); $i++) {
$fid = theme_get_setting('slide_image_path' . $i, 'robotic');
$activeSlide = '';
if ($i == 1) {
$activeSlide = 'active';
}
if (!empty($fid)) {
//$file = file_load($fid[0]);
//$uri = $file->getFileUri();
if (!empty(\Drupal\file\Entity\File::load($fid[0]))) {
$file = \Drupal\file\Entity\File::load($fid[0])->getFileUri();
$path = file_create_url($file);
}
} else {
$path = base_path() . drupal_get_path('theme', 'robotic') . theme_get_setting('slide_image_path_' . $i, 'robotic');
} //end if
//BG imgage
/*$fidbg = theme_get_setting('slide_bg_path_' . $i, 'robotic');
$noslideimg = ' no-image';
if (!empty($fidbg)) {
//$filebg = file_load($fidbg[0]);
//$uribg = $filebg->getFileUri();
if (!empty(\Drupal\file\Entity\File::load($fidbg[0]))) {
$filebg = \Drupal\file\Entity\File::load($fidbg[0])->getFileUri();
$pathbg = file_create_url($filebg);
$bgimg = '<img class="slider-bg-img" src="' . $pathbg . '" alt="image01" />';
}
$noslideimg ='';
} else {
$pathbg = base_path() . drupal_get_path('theme', 'robotic') . '/images/slider/slide-'. $i .'-bg.png';
$bgimg = '<img class="slider-bg-img" src="' . $pathbg . '" alt="image01" />';
} //end if*/
$slider_content[$i] = '<div class="item ' . $activeSlide . '" data-id="' . $i . '" style="background:' . theme_get_setting('slide_color_' . $i, 'robotic') . '">
<div class="carousel-caption">
<div class="container"><div class="col-md-6 text-left">
<h3 class="title animated zoomIn">' . wordwrap(theme_get_setting('slide_title_' . $i, 'robotic'), 20, "<br>") . '</h3>
<p class="text animated zoomIn">' . wordwrap(theme_get_setting('slide_description_' . $i, 'robotic'), 60, "<br>") . '</p>
<a href=' . theme_get_setting('slide_url_' . $i, 'robotic') . ' class="da-link animated rubberBand">Read more</a>
</div><div class="col-md-6 text-right">
<img class="animated zoomInRight" src="' . $path . '" alt="image01" />
</div></div>
</div>
</div>';
}
return $slider_content;
}
// slider indicator callback
function robotic_get_slider_indicator()
{
$slider_indicator = array();
for ($i = 1; $i <= theme_get_setting('slide_number', 'robotic'); $i++) {
$active = '';
if ($i == 1) {
$active = 'active';
}
$slider_indicator[$i] = '<li data-target="#roboticCarousel" data-slide-to="' . $i . '" class="' . $active . '"></li>';
}
return $slider_indicator;
}
// social links callback
function robotic_get_social_links()
{
$slcontent = '<div class="social-section"><div class="social-links"><ul>';
for ($i = 1; $i <= SOCIAL_ICON_COUNT; $i++) {
if (!empty(theme_get_setting("social_class_{$i}"))) {
$slcontent .= '<li><a href="' . theme_get_setting("social_links_{$i}") . '" target="_blank"><i class="fa ' . theme_get_setting("social_class_{$i}") . '"></i></a></li>';
}
}
$slcontent .= '</ul></div></div>';
return $slcontent;
}