326854cf43c7c99804c32705a016728656aca30a
[yaffs-website] / web / modules / contrib / superfish / src / Plugin / Block / SuperfishBlock.php
1 <?php
2
3 namespace Drupal\superfish\Plugin\Block;
4
5 use Drupal\system\Plugin\Block\SystemMenuBlock;
6 use Drupal\Core\Menu\MenuTreeParameters;
7 use Drupal\Core\Form\FormStateInterface;
8 use Drupal\Component\Utility\Html;
9
10 /**
11  * Provides a "Superfish" block.
12  *
13  * @Block(
14  *   id = "superfish",
15  *   admin_label = @Translation("Superfish"),
16  *   cache = -1,
17  *   category = @Translation("Superfish"),
18  *   deriver = "Drupal\system\Plugin\Derivative\SystemMenuBlock"
19  * )
20  */
21 class SuperfishBlock extends SystemMenuBlock {
22
23   /**
24    * Overrides \Drupal\block\BlockBase::blockForm().
25    */
26   public function blockForm($form, FormStateInterface $form_state) {
27     $form = parent::blockForm($form, $form_state);
28     $defaults = $this->defaultConfiguration();
29     $form['sf'] = [
30       '#type' => 'details',
31       '#title' => $this->t('Block settings'),
32       '#open' => TRUE,
33     ];
34     $description = sprintf('<em>(%s: %s)</em>',
35       $this->t('Default'),
36       $this->t('Horizontal (single row)')
37     );
38     $form['sf']['superfish_type'] = [
39       '#type' => 'radios',
40       '#title' => $this->t('Menu type'),
41       '#description' => $description,
42       '#default_value' => $this->configuration['menu_type'],
43       '#options' => [
44         'horizontal' => $this->t('Horizontal (single row)'),
45         'navbar' => $this->t('Horizontal (double row)'),
46         'vertical' => $this->t('Vertical (stack)'),
47       ],
48     ];
49     $description = sprintf('<em>(%s: %s)</em>',
50       $this->t('Default'),
51       $this->t('None')
52     );
53     $form['sf']['superfish_style'] = [
54       '#type' => 'select',
55       '#title' => $this->t('Style'),
56       '#description' => $description,
57       '#default_value' => $this->configuration['style'],
58       '#options' => [
59         'none' => $this->t('None'),
60         'default' => $this->t('Default'),
61         'black' => $this->t('Black'),
62         'blue' => $this->t('Blue'),
63         'coffee' => $this->t('Coffee'),
64         'white' => $this->t('White'),
65       ],
66     ];
67     $form['sf']['superfish_arrow'] = [
68       '#type' => 'checkbox',
69       '#title' => $this->t('Add arrows to parent menus'),
70       '#default_value' => $this->configuration['arrow'],
71     ];
72     $form['sf']['superfish_shadow'] = [
73       '#type' => 'checkbox',
74       '#title' => $this->t('Drop shadows'),
75       '#default_value' => $this->configuration['shadow'],
76     ];
77     if (count(superfish_effects()) == 4) {
78       $easing_instructions = $this->t('jQuery Easing plugin is not installed.');
79     }
80     else {
81       $easing_instructions = $this->t("The plugin provides a handful number of animation effects, they can be used by uploading the 'jquery.easing.js' file to the libraries directory within the 'easing' directory (for example: libraries/easing/jquery.easing.js). Refresh this page after the plugin is uploaded, this will make more effects available in the above list.");
82     }
83     $description = sprintf('<em>(%s: %s)</em><br>%s<br>',
84       $this->t('Default'),
85       $this->t('Vertical'),
86       $easing_instructions
87     );
88     $form['sf']['superfish_slide'] = [
89       '#type' => 'select',
90       '#title' => $this->t('Slide-in effect'),
91       '#description' => $description,
92       '#default_value' => $this->configuration['slide'],
93       '#options' => superfish_effects(),
94     ];
95     $form['sf-plugins'] = [
96       '#type' => 'details',
97       '#title' => $this->t('Superfish plugins'),
98       '#open' => TRUE,
99     ];
100     $description = sprintf('%s <em>(%s: %s)</em>',
101       $this->t('Relocates sub-menus when they would otherwise appear outside the browser window area.'),
102       $this->t('Default'),
103       $this->t('enabled')
104     );
105     $form['sf-plugins']['superfish_supposition'] = [
106       '#type' => 'checkbox',
107       '#title' => $this->t('jQuery Supposition'),
108       '#description' => $description,
109       '#default_value' => $this->configuration['supposition'],
110     ];
111     $description = sprintf('%s <em>(%s: %s)</em>',
112       $this->t("Prevents accidental firing of animations by waiting until the user's mouse slows down enough, hence determinig user's <em>intent</em>."),
113       $this->t('Default'),
114       $this->t('enabled')
115     );
116     $form['sf-plugins']['superfish_hoverintent'] = [
117       '#type' => 'checkbox',
118       '#title' => $this->t('jQuery hoverIntent'),
119       '#description' => $description,
120       '#default_value' => $this->configuration['hoverintent'],
121     ];
122     $description = sprintf('%s <em>(%s)</em>',
123       $this->t('<strong>sf-Touchscreen</strong> provides touchscreen compatibility.'),
124       $this->t('The first click on a parent hyperlink shows its children and the second click opens the hyperlink.')
125     );
126     $form['sf-plugins']['sf-touchscreen'] = [
127       '#type' => 'details',
128       '#title' => $this->t('sf-Touchscreen'),
129       '#description' => $description,
130       '#open' => FALSE,
131     ];
132     $default = sprintf('%s <em>(%s)</em>',
133       $this->t('Disable'),
134       $this->t('Default')
135     );
136     $form['sf-plugins']['sf-touchscreen']['superfish_touch'] = [
137       '#type' => 'radios',
138       '#default_value' => $this->configuration['touch'],
139       '#options' => [
140         0 => $default,
141         1 => $this->t('Enable jQuery sf-Touchscreen plugin for this menu.'),
142         2 => $this->t("Enable jQuery sf-Touchscreen plugin for this menu depending on the user's Web browser <strong>window width</strong>."),
143         3 => $this->t("Enable jQuery sf-Touchscreen plugin for this menu depending on the user's Web browser <strong>user agent</strong>."),
144       ],
145     ];
146     $default = sprintf('%s <em>(%s)</em>',
147       $this->t('Hiding the sub-menu on the second tap, adding cloned parent links to the top of sub-menus as well.'),
148       $this->t('Default')
149     );
150     $form['sf-plugins']['sf-touchscreen']['superfish_touchbh'] = [
151       '#type' => 'radios',
152       '#title' => 'Select a behaviour',
153       '#description' => $this->t('Using this plugin, the first click or tap will expand the sub-menu, here you can choose what a second click or tap should do.'),
154       '#default_value' => $this->configuration['touchbh'],
155       '#options' => [
156         0 => $this->t('Opening the parent menu item link on the second tap.'),
157         1 => $this->t('Hiding the sub-menu on the second tap.'),
158         2 => $default,
159       ],
160     ];
161     $description = sprintf('%s<br><br>%s<br><code>&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;</code>',
162       $this->t("sf-Touchscreen will be enabled only if the width of user's Web browser window is smaller than the below value."),
163       $this->t('Please note that in most cases such a meta tag is necessary for this feature to work properly:')
164     );
165     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth'] = [
166       '#type' => 'details',
167       '#title' => $this->t('Window width settings'),
168       '#description' => $description,
169       '#open' => TRUE,
170     ];
171     $description = sprintf('%s <em>(%s: 768)</em>',
172       $this->t('Also known as "Breakpoint".'),
173       $this->t('Default')
174     );
175     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth']['superfish_touchbp'] = [
176       '#type' => 'number',
177       '#description' => $description,
178       '#default_value' => $this->configuration['touchbp'],
179       '#field_suffix' => $this->t('pixels'),
180       '#size' => 10,
181     ];
182     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent'] = [
183       '#type' => 'details',
184       '#title' => $this->t('User agent settings'),
185       '#open' => TRUE,
186     ];
187     $default = sprintf('%s <em>(%s) (%s)</em>',
188       $this->t('Use the pre-defined list of the <strong>user agents</strong>.'),
189       $this->t('Default'),
190       $this->t('Recommended')
191     );
192     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchua'] = [
193       '#type' => 'radios',
194       '#default_value' => $this->configuration['touchua'],
195       '#options' => [
196         0 => $default,
197         1 => $this->t('Use the custom list of the <strong>user agents</strong>.'),
198       ],
199     ];
200     if (isset($_SERVER['HTTP_USER_AGENT'])) {
201       $user_agent = sprintf('<br><strong>%s</strong> %s',
202         $this->t('UA string of the current Web browser:'),
203         $_SERVER['HTTP_USER_AGENT']
204       );
205     }
206     else {
207       $user_agent = '';
208     }
209     $description = sprintf('%s <em>(%s: %s)</em><br>%s:<ul>
210     <li>iPhone*Android*iPad <em><sup>(%s)</sup></em></li>
211     <li>Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2
212     (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0 * Mozilla/5.0
213     (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10
214     (KHTML, like Gecko) Mobile/7B405</li>
215     </ul>%s',
216       $this->t('Could be partial or complete. (Asterisk separated)'),
217       $this->t('Default'),
218       $this->t('empty'),
219       $this->t('Examples'),
220       $this->t('Recommended'),
221       $user_agent
222     );
223     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchual'] = [
224       '#type' => 'textfield',
225       '#title' => $this->t('Custom list of the user agents'),
226       '#description' => $description,
227       '#default_value' => $this->configuration['touchual'],
228       '#size' => 100,
229       '#maxlength' => 2000,
230     ];
231     $description = sprintf('<em>(%s: %s)</em>',
232       $this->t('Default'),
233       $this->t('Client-side (JavaScript)')
234     );
235     $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchuam'] = [
236       '#type' => 'select',
237       '#title' => $this->t('<strong>User agent</strong> detection method'),
238       '#description' => $description,
239       '#default_value' => $this->configuration['touchuam'],
240       '#options' => [
241         0 => $this->t('Client-side (JavaScript)'),
242         1 => $this->t('Server-side (PHP)'),
243       ],
244     ];
245     $form['sf-plugins']['sf-smallscreen'] = [
246       '#type' => 'details',
247       '#title' => $this->t('sf-Smallscreen'),
248       '#description' => $this->t('<strong>sf-Smallscreen</strong> provides small-screen compatibility for your menus.'),
249       '#open' => FALSE,
250     ];
251     $default = sprintf('%s <em>(%s)</em>',
252       $this->t("Enable jQuery sf-Smallscreen plugin for this menu depending on the user's Web browser <strong>window width</strong>."),
253       $this->t('Default')
254     );
255     $form['sf-plugins']['sf-smallscreen']['superfish_small'] = [
256       '#type' => 'radios',
257       '#default_value' => $this->configuration['small'],
258       '#options' => [
259         0 => sprintf('%s.', $this->t('Disable')),
260         1 => $this->t('Enable jQuery sf-Smallscreen plugin for this menu.'),
261         2 => $default,
262         3 => $this->t("Enable jQuery sf-Smallscreen plugin for this menu depending on the user's Web browser <strong>user agent</strong>."),
263       ],
264     ];
265     $description = sprintf('%s<br><br>%s<br><code>&lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt;</code>',
266       $this->t("sf-Smallscreen will be enabled only if the width of user's Web browser window is smaller than the below value."),
267       $this->t('Please note that in most cases such a meta tag is necessary for this feature to work properly:')
268     );
269     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth'] = [
270       '#type' => 'details',
271       '#title' => $this->t('Window width settings'),
272       '#description' => $description,
273       '#open' => TRUE,
274     ];
275     $description = sprintf('%s <em>(%s: 768)</em>',
276       $this->t('Also known as "Breakpoint".'),
277       $this->t('Default')
278     );
279     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth']['superfish_smallbp'] = [
280       '#type' => 'number',
281       '#description' => $description,
282       '#default_value' => $this->configuration['smallbp'],
283       '#field_suffix' => $this->t('pixels'),
284       '#size' => 10,
285     ];
286     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent'] = [
287       '#type' => 'details',
288       '#title' => $this->t('User agent settings'),
289       '#open' => TRUE,
290     ];
291     $default = sprintf('%s <em>(%s) (%s)</em>',
292       $this->t('Use the pre-defined list of the <strong>user agents</strong>.'),
293       $this->t('Default'),
294       $this->t('Recommended')
295     );
296     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smallua'] = [
297       '#type' => 'radios',
298       '#default_value' => $this->configuration['smallua'],
299       '#options' => [
300         0 => $default,
301         1 => $this->t('Use the custom list of the <strong>user agents</strong>.'),
302       ],
303     ];
304     if (isset($_SERVER['HTTP_USER_AGENT'])) {
305       $user_agent = sprintf('<br><strong>%s</strong> %s',
306         $this->t('UA string of the current Web browser:'),
307         $_SERVER['HTTP_USER_AGENT']
308       );
309     }
310     else {
311       $user_agent = '';
312     }
313     $description = sprintf('%s <em>(%s: %s)</em><br>%s:<ul>
314     <li>iPhone*Android*iPad <em><sup>(%s)</sup></em></li>
315     <li>Mozilla/5.0 (webOS/1.4.0; U; en-US) AppleWebKit/532.2
316     (KHTML, like Gecko) Version/1.0 Safari/532.2 Pre/1.0 * Mozilla/5.0
317     (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10
318     (KHTML, like Gecko) Mobile/7B405</li>
319     </ul>%s',
320       $this->t('Could be partial or complete. (Asterisk separated)'),
321       $this->t('Default'),
322       $this->t('empty'),
323       $this->t('Examples'),
324       $this->t('Recommended'),
325       $user_agent
326     );
327     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smallual'] = [
328       '#type' => 'textfield',
329       '#title' => $this->t('Custom list of the user agents'),
330       '#description' => $description,
331       '#default_value' => $this->configuration['smallual'],
332       '#size' => 100,
333       '#maxlength' => 2000,
334     ];
335     $description = sprintf('<em>(%s: %s)</em>',
336       $this->t('Default'),
337       $this->t('Client-side (JavaScript)')
338     );
339     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smalluam'] = [
340       '#type' => 'select',
341       '#title' => $this->t('<strong>User agent</strong> detection method'),
342       '#description' => $description,
343       '#default_value' => $this->configuration['smalluam'],
344       '#options' => [
345         0 => $this->t('Client-side (JavaScript)'),
346         1 => $this->t('Server-side (PHP)'),
347       ],
348     ];
349     $default = sprintf('%s <em>(%s)</em>',
350       $this->t('Convert the menu to an accordion menu.'),
351       $this->t('Default')
352     );
353     $form['sf-plugins']['sf-smallscreen']['superfish_smallact'] = [
354       '#type' => 'radios',
355       '#title' => $this->t('Select a type'),
356       '#default_value' => $this->configuration['smallact'],
357       '#options' => [
358         1 => $default,
359         0 => $this->t('Convert the menu to a &lt;select&gt; element.'),
360       ],
361     ];
362     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select'] = [
363       '#type' => 'details',
364       '#title' => $this->t('&lt;select&gt; settings'),
365       '#open' => FALSE,
366     ];
367     $description = sprintf('%s <em>(%s: %s)</em><br>%s: <em> - %s - </em>',
368       $this->t('By default the first item in the &lt;select&gt; element will be the name of the parent menu or the title of this block, you can change this by setting a custom title.'),
369       $this->t('Default'),
370       $this->t('empty'),
371       $this->t('Example'),
372       $this->t('Main Menu')
373     );
374     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['superfish_smallset'] = [
375       '#type' => 'textfield',
376       '#title' => $this->t('&lt;select&gt; title'),
377       '#description' => $description,
378       '#default_value' => $this->configuration['smallset'],
379       '#size' => 50,
380       '#maxlength' => 500,
381     ];
382     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['superfish_smallasa'] = [
383       '#type' => 'checkbox',
384       '#title' => $this->t('Add <em>selected</em> attribute to the &lt;option&gt; element with the class <strong>active</strong> .'),
385       '#description' => $this->t('Makes pre-selected the item linked to the active page when the page loads.'),
386       '#default_value' => $this->configuration['smallasa'],
387     ];
388     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more'] = [
389       '#type' => 'details',
390       '#title' => $this->t('More'),
391       '#open' => FALSE,
392     ];
393     $title = sprintf('%s <em>(%s: %s)</em>',
394       $this->t('Copy the main &lt;ul&gt; classes to the &lt;select&gt;.'),
395       $this->t('Default'),
396       $this->t('disabled')
397     );
398     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallcmc'] = [
399       '#type' => 'checkbox',
400       '#title' => $title,
401       '#default_value' => $this->configuration['smallcmc'],
402     ];
403     $description = sprintf('%s <em>(%s: %s)</em>',
404       $this->t('Comma separated'),
405       $this->t('Default'),
406       $this->t('empty')
407     );
408     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallecm'] = [
409       '#type' => 'textfield',
410       '#title' => $this->t('Exclude these classes from the &lt;select&gt; element'),
411       '#description' => $description,
412       '#default_value' => $this->configuration['smallecm'],
413       '#size' => 100,
414       '#maxlength' => 1000,
415       '#states' => [
416         'enabled' => [
417           ':input[name="superfish_smallcmc"]' => [
418             'checked' => TRUE,
419           ],
420         ],
421       ],
422     ];
423
424     $title = sprintf('%s <em>(%s: %s)</em>',
425       $this->t('Copy the hyperlink classes to the &lt;option&gt; elements of the &lt;select&gt;.'),
426       $this->t('Default'),
427       $this->t('disabled')
428     );
429     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallchc'] = [
430       '#type' => 'checkbox',
431       '#title' => $title,
432       '#default_value' => $this->configuration['smallchc'],
433     ];
434     $description = sprintf('%s <em>(%s: %s)</em>',
435       $this->t('Comma separated'),
436       $this->t('Default'),
437       $this->t('empty')
438     );
439     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallech'] = [
440       '#type' => 'textfield',
441       '#title' => $this->t('Exclude these classes from the &lt;option&gt; elements of the &lt;select&gt;'),
442       '#description' => $description,
443       '#default_value' => $this->configuration['smallech'],
444       '#size' => 100,
445       '#maxlength' => 1000,
446       '#states' => [
447         'enabled' => [
448           ':input[name="superfish_smallchc"]' => [
449             'checked' => TRUE,
450           ],
451         ],
452       ],
453     ];
454     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallicm'] = [
455       '#type' => 'textfield',
456       '#title' => $this->t('Include these classes in the &lt;select&gt; element'),
457       '#description' => $description,
458       '#default_value' => $this->configuration['smallicm'],
459       '#size' => 100,
460       '#maxlength' => 1000,
461     ];
462     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallich'] = [
463       '#type' => 'textfield',
464       '#title' => $this->t('Include these classes in the &lt;option&gt; elements of the &lt;select&gt;'),
465       '#description' => $description,
466       '#default_value' => $this->configuration['smallich'],
467       '#size' => 100,
468       '#maxlength' => 1000,
469     ];
470     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-accordion'] = [
471       '#type' => 'details',
472       '#title' => $this->t('Accordion settings'),
473       '#open' => FALSE,
474     ];
475     $description = sprintf('%s <em>(%s: %s)</em><br>%s: <em>%s</em>.',
476       $this->t('By default the caption of the accordion toggle switch will be the name of the parent menu or the title of this block, you can change this by setting a custom title.'),
477       $this->t('Default'),
478       $this->t('empty'),
479       $this->t('Example'),
480       $this->t('Menu')
481     );
482     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-accordion']['superfish_smallamt'] = [
483       '#type' => 'textfield',
484       '#title' => $this->t('Accordion menu title'),
485       '#description' => $description,
486       '#default_value' => $this->configuration['smallamt'],
487       '#size' => 50,
488       '#maxlength' => 500,
489     ];
490     $default = sprintf('%s <em>(%s)</em>',
491       $this->t('Use parent menu items as buttons, add cloned parent links to sub-menus as well.'),
492       $this->t('Default')
493     );
494     $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-accordion']['superfish_smallabt'] = [
495       '#type' => 'radios',
496       '#title' => $this->t('Accordion button type'),
497       '#default_value' => $this->configuration['smallabt'],
498       '#options' => [
499         0 => $this->t('Use parent menu items as buttons.'),
500         1 => $default,
501         2 => $this->t('Create new links next to parent menu item links and use them as buttons.'),
502       ],
503     ];
504     $form['sf-plugins']['sf-supersubs'] = [
505       '#type' => 'details',
506       '#title' => $this->t('Supersubs'),
507       '#description' => $this->t('<strong>Supersubs</strong> makes it possible to define custom widths for your menus.'),
508       '#open' => FALSE,
509     ];
510     $form['sf-plugins']['sf-supersubs']['superfish_supersubs'] = [
511       '#type' => 'checkbox',
512       '#title' => $this->t('Enable Supersubs for this menu.'),
513       '#default_value' => $this->configuration['supersubs'],
514     ];
515     $description = sprintf('%s <em>(%s: 12)</em>',
516       $this->t('Minimum width for sub-menus, in <strong>em</strong> units.'),
517       $this->t('Default')
518     );
519     $form['sf-plugins']['sf-supersubs']['superfish_minwidth'] = [
520       '#type' => 'number',
521       '#title' => $this->t('Minimum width'),
522       '#description' => $description,
523       '#default_value' => $this->configuration['minwidth'],
524       '#size' => 10,
525     ];
526     $description = sprintf('%s <em>(%s: 27)</em>',
527       $this->t('Maximum width for sub-menus, in <strong>em</strong> units.'),
528       $this->t('Default')
529     );
530     $form['sf-plugins']['sf-supersubs']['superfish_maxwidth'] = [
531       '#type' => 'number',
532       '#title' => $this->t('Maximum width'),
533       '#description' => $description,
534       '#default_value' => $this->configuration['maxwidth'],
535       '#size' => 10,
536     ];
537     $form['sf-multicolumn'] = [
538       '#type' => 'details',
539       '#description' => $this->t('Please refer to the Superfish module documentation for how you should setup multi-column sub-menus.'),
540       '#title' => $this->t('Multi-column sub-menus'),
541       '#open' => FALSE,
542     ];
543     $form['sf-multicolumn']['superfish_multicolumn'] = [
544       '#type' => 'checkbox',
545       '#title' => $this->t('Enable multi-column sub-menus.'),
546       '#default_value' => $this->configuration['multicolumn'],
547     ];
548     $description = sprintf('%s <em>(%s: 1)</em>',
549       $this->t('The depth of the first instance of multi-column sub-menus.'),
550       $this->t('Default')
551     );
552     $form['sf-multicolumn']['superfish_multicolumn_depth'] = [
553       '#type' => 'select',
554       '#title' => $this->t('Start from depth'),
555       '#description' => $description,
556       '#default_value' => $this->configuration['multicolumn_depth'],
557       '#options' => array_combine(range(1, 10), range(1, 10)),
558     ];
559     $description = sprintf('%s <em>(%s: 1)</em>',
560       $this->t('The amount of sub-menu levels that will be included in the multi-column sub-menu.'),
561       $this->t('Default')
562     );
563     $form['sf-multicolumn']['superfish_multicolumn_levels'] = [
564       '#type' => 'select',
565       '#title' => $this->t('Levels'),
566       '#description' => $description,
567       '#default_value' => $this->configuration['multicolumn_levels'],
568       '#options' => array_combine(range(1, 10), range(1, 10)),
569     ];
570     $form['sf-advanced'] = [
571       '#type' => 'details',
572       '#title' => $this->t('Advanced settings'),
573       '#open' => FALSE,
574     ];
575     $form['sf-advanced']['sf-settings'] = [
576       '#type' => 'details',
577       '#title' => $this->t('Superfish'),
578       '#open' => FALSE,
579     ];
580     $description = sprintf('%s <em>(%s: fast)</em>',
581       $this->t('The speed of the animation either in <strong>milliseconds</strong> or pre-defined values (<strong>slow, normal, fast</strong>).'),
582       $this->t('Default')
583     );
584     $form['sf-advanced']['sf-settings']['superfish_speed'] = [
585       '#type' => 'textfield',
586       '#title' => $this->t('Animation speed'),
587       '#description' => $description,
588       '#default_value' => $this->configuration['speed'],
589       '#size' => 15,
590     ];
591     $description = sprintf('%s <em>(%s: 800)</em>',
592       $this->t('The delay in <strong>milliseconds</strong> that the mouse can remain outside a sub-menu without it closing.'),
593       $this->t('Default')
594     );
595     $form['sf-advanced']['sf-settings']['superfish_delay'] = [
596       '#type' => 'number',
597       '#title' => $this->t('Mouse delay'),
598       '#description' => $description,
599       '#default_value' => $this->configuration['delay'],
600       '#size' => 15,
601     ];
602     $description = sprintf('%s <em>(%s: 1)</em><br>%s',
603       $this->t('The amount of sub-menu levels that remain open or are restored using the ".active-trail" class.'),
604       $this->t('Default'),
605       $this->t('Change this setting <strong>only and only</strong> if you are <strong>totally sure</strong> of what you are doing.')
606     );
607     $form['sf-advanced']['sf-settings']['superfish_pathlevels'] = [
608       '#type' => 'select',
609       '#title' => $this->t('Path levels'),
610       '#description' => $description,
611       '#default_value' => $this->configuration['pathlevels'],
612       '#options' => array_combine(range(0, 10), range(0, 10)),
613     ];
614     $form['sf-advanced']['sf-hyperlinks'] = [
615       '#type' => 'details',
616       '#title' => $this->t('Hyperlinks'),
617       '#open' => TRUE,
618     ];
619     $description = sprintf('%s <em>(%s: %s)</em>',
620       $this->t('By enabling this option, only parent menu items with <em>Expanded</em> option enabled will have their submenus appear.'),
621       $this->t('Default'),
622       $this->t('disabled')
623     );
624     $form['sf-advanced']['sf-hyperlinks']['superfish_expanded'] = [
625       '#type' => 'checkbox',
626       '#title' => $this->t('Take "Expanded" option into effect.'),
627       '#description' => $description,
628       '#default_value' => $this->configuration['expanded'],
629     ];
630     $description = sprintf('%s <em>(%s: %s)</em>',
631       $this->t('Add cloned parent links to the top of sub-menus.'),
632       $this->t('Default'),
633       $this->t('disabled')
634     );
635     $form['sf-advanced']['sf-hyperlinks']['superfish_clone_parent'] = [
636       '#type' => 'checkbox',
637       '#title' => $description,
638       '#default_value' => $this->configuration['clone_parent'],
639     ];
640     $description = sprintf('%s <em>(%s: %s)</em>',
641       $this->t('Disable hyperlink descriptions ("title" attribute)'),
642       $this->t('Default'),
643       $this->t('disabled')
644     );
645     $form['sf-advanced']['sf-hyperlinks']['superfish_hide_linkdescription'] = [
646       '#type' => 'checkbox',
647       '#title' => $description,
648       '#default_value' => $this->configuration['hide_linkdescription'],
649     ];
650     $description = sprintf('%s <em>(%s: %s)</em>',
651       $this->t('Insert hyperlink descriptions ("title" attribute) into hyperlink texts.'),
652       $this->t('Default'),
653       $this->t('disabled')
654     );
655     $form['sf-advanced']['sf-hyperlinks']['superfish_add_linkdescription'] = [
656       '#type' => 'checkbox',
657       '#title' => $description,
658       '#default_value' => $this->configuration['add_linkdescription'],
659     ];
660     $title = sprintf('%s <em>(sf-depth-1, sf-depth-2, sf-depth-3, ...)</em> <em>(%s: %s)</em>',
661       $this->t('Add item depth classes to menu items and their hyperlinks.'),
662       $this->t('Default'),
663       $this->t('enabled')
664     );
665     $form['sf-advanced']['sf-hyperlinks']['superfish_itemdepth'] = [
666       '#type' => 'checkbox',
667       '#title' => $title,
668       '#default_value' => $this->configuration['link_depth_class'],
669     ];
670     $form['sf-advanced']['sf-custom-classes'] = [
671       '#type' => 'details',
672       '#title' => $this->t('Custom classes'),
673       '#open' => TRUE,
674     ];
675     $description = sprintf('%s <em>(%s: %s)</em><br>%s: top-menu category-science',
676       $this->t('(Space separated, without dots)'),
677       $this->t('Default'),
678       $this->t('empty'),
679       $this->t('Example')
680     );
681     $form['sf-advanced']['sf-custom-classes']['superfish_ulclass'] = [
682       '#type' => 'textfield',
683       '#title' => $this->t('For the main UL'),
684       '#description' => $description,
685       '#default_value' => $this->configuration['custom_list_class'],
686       '#size' => 50,
687       '#maxlength' => 1000,
688     ];
689     $description = sprintf('%s <em>(%s: %s)</em><br>%s: science-sub',
690       $this->t('(Space separated, without dots)'),
691       $this->t('Default'),
692       $this->t('empty'),
693       $this->t('Example')
694     );
695     $form['sf-advanced']['sf-custom-classes']['superfish_liclass'] = [
696       '#type' => 'textfield',
697       '#title' => $this->t('For the list items'),
698       '#description' => $description,
699       '#default_value' => $this->configuration['custom_item_class'],
700       '#size' => 50,
701       '#maxlength' => 1000,
702     ];
703     $description = sprintf('%s <em>(%s: %s)</em><br>%s: science-link',
704       $this->t('(Space separated, without dots)'),
705       $this->t('Default'),
706       $this->t('empty'),
707       $this->t('Example')
708     );
709     $form['sf-advanced']['sf-custom-classes']['superfish_hlclass'] = [
710       '#type' => 'textfield',
711       '#title' => $this->t('For the hyperlinks'),
712       '#description' => $description,
713       '#default_value' => $this->configuration['custom_link_class'],
714       '#size' => 50,
715       '#maxlength' => 1000,
716     ];
717     return $form;
718   }
719
720   /**
721    * Overrides \Drupal\block\BlockBase::blockValiate().
722    */
723   public function blockValidate($form, FormStateInterface $form_state) {
724     $touch = $form_state->getValue([
725       'sf-plugins',
726       'sf-touchscreen',
727       'sf-touchscreen-useragent',
728       'superfish_touch',
729     ]);
730     $touchbp = $form_state->getValue([
731       'sf-plugins',
732       'sf-touchscreen',
733       'sf-touchscreen-windowwidth',
734       'superfish_touchbp',
735     ]);
736     $touchua = $form_state->getValue([
737       'sf-plugins',
738       'sf-touchscreen',
739       'sf-touchscreen-useragent',
740       'superfish_touchua',
741     ]);
742     $touchual = $form_state->getValue([
743       'sf-plugins',
744       'sf-touchscreen',
745       'sf-touchscreen-useragent',
746       'superfish_touchual',
747     ]);
748     $small = $form_state->getValue([
749       'sf-plugins',
750       'sf-smallscreen',
751       'sf-smallscreen-useragent',
752       'superfish_small',
753     ]);
754     $smallbp = $form_state->getValue([
755       'sf-plugins',
756       'sf-smallscreen',
757       'sf-smallscreen-windowwidth',
758       'superfish_smallbp',
759     ]);
760     $smallua = $form_state->getValue([
761       'sf-plugins',
762       'sf-smallscreen',
763       'sf-smallscreen-useragent',
764       'superfish_smallua',
765     ]);
766     $smallual = $form_state->getValue([
767       'sf-plugins',
768       'sf-smallscreen',
769       'sf-smallscreen-useragent',
770       'superfish_smallual',
771     ]);
772     $minwidth = $form_state->getValue([
773       'sf-plugins',
774       'sf-supersubs',
775       'superfish_minwidth',
776     ]);
777     $maxwidth = $form_state->getValue([
778       'sf-plugins',
779       'sf-supersubs',
780       'superfish_maxwidth',
781     ]);
782     $speed = $form_state->getValue([
783       'sf-advanced',
784       'sf-settings',
785       'superfish_speed',
786     ]);
787     $delay = $form_state->getValue([
788       'sf-advanced',
789       'sf-settings',
790       'superfish_delay',
791     ]);
792
793     if (!is_numeric($speed) && !in_array($speed, ['slow', 'normal', 'fast'])) {
794       $form_state->setErrorByName('superfish_speed', t('Unacceptable value entered for the "Animation speed" option.'));
795     }
796     if (!is_numeric($delay)) {
797       $form_state->setErrorByName('superfish_delay', t('Unacceptable value entered for the "Mouse delay" option.'));
798     }
799     if ($touch == 2 && $touchbp == '') {
800       $form_state->setErrorByName('superfish_touchbp', t('"sfTouchscreen Breakpoint" option cannot be empty.'));
801     }
802     if (!is_numeric($touchbp)) {
803       $form_state->setErrorByName('superfish_touchbp', t('Unacceptable value enterd for the "sfTouchscreen Breakpoint" option.'));
804     }
805     if ($touch == 3 && $touchua == 1 && $touchual == '') {
806       $form_state->setErrorByName('superfish_touchual', t('List of the touch-screen user agents cannot be empty.'));
807     }
808     if ($small == 2 && $smallbp == '') {
809       $form_state->setErrorByName('superfish_smallbp', t('"sfSmallscreen Breakpoint" option cannot be empty.'));
810     }
811     if (!is_numeric($smallbp)) {
812       $form_state->setErrorByName('superfish_smallbp', t('Unacceptable value entered for the "sfSmallscreen Breakpoint" option.'));
813     }
814     if ($small == 3 && $smallua == 1 && $smallual == '') {
815       $form_state->setErrorByName('superfish_smallual', t('List of the small-screen user agents cannot be empty.'));
816     }
817
818     $supersubs_error = FALSE;
819     if (!is_numeric($minwidth)) {
820       $form_state->setErrorByName('superfish_minwidth', t('Unacceptable value entered for the "Supersubs minimum width" option.'));
821       $supersubs_error = TRUE;
822     }
823     if (!is_numeric($maxwidth)) {
824       $form_state->setErrorByName('superfish_maxwidth', t('Unacceptable value entered for the "Supersubs maximum width" option.'));
825       $supersubs_error = TRUE;
826     }
827     if ($supersubs_error !== TRUE && $minwidth > $maxwidth) {
828       $form_state->setErrorByName('superfish_maxwidth', t('Supersubs "maximum width" has to be bigger than the "minimum width".'));
829     }
830   }
831
832   /**
833    * Overrides \Drupal\block\BlockBase::blockSubmit().
834    */
835   public function blockSubmit($form, FormStateInterface $form_state) {
836
837     $this->configuration['level'] = $form_state->getValue('level');
838     $this->configuration['depth'] = $form_state->getValue('depth');
839     $this->configuration['menu_type'] = $form_state->getValue([
840       'sf',
841       'superfish_type',
842     ]);
843     $this->configuration['style'] = $form_state->getValue([
844       'sf',
845       'superfish_style',
846     ]);
847     $this->configuration['arrow'] = $form_state->getValue([
848       'sf',
849       'superfish_arrow',
850     ]);
851     $this->configuration['shadow'] = $form_state->getValue([
852       'sf',
853       'superfish_shadow',
854     ]);
855     $this->configuration['slide'] = $form_state->getValue([
856       'sf',
857       'superfish_slide',
858     ]);
859
860     $this->configuration['supposition'] = $form_state->getValue([
861       'sf-plugins',
862       'superfish_supposition',
863     ]);
864     $this->configuration['hoverintent'] = $form_state->getValue([
865       'sf-plugins',
866       'superfish_hoverintent',
867     ]);
868
869     $this->configuration['touch'] = $form_state->getValue([
870       'sf-plugins',
871       'sf-touchscreen',
872       'superfish_touch',
873     ]);
874     $this->configuration['touchbh'] = $form_state->getValue([
875       'sf-plugins',
876       'sf-touchscreen',
877       'superfish_touchbh',
878     ]);
879     $this->configuration['touchbp'] = $form_state->getValue([
880       'sf-plugins',
881       'sf-touchscreen',
882       'sf-touchscreen-windowwidth',
883       'superfish_touchbp',
884     ]);
885     $this->configuration['touchua'] = $form_state->getValue([
886       'sf-plugins',
887       'sf-touchscreen',
888       'sf-touchscreen-useragent',
889       'superfish_touchua',
890     ]);
891     $this->configuration['touchual'] = $form_state->getValue([
892       'sf-plugins',
893       'sf-touchscreen',
894       'sf-touchscreen-useragent',
895       'superfish_touchual',
896     ]);
897     $this->configuration['touchuam'] = $form_state->getValue([
898       'sf-plugins',
899       'sf-touchscreen',
900       'sf-touchscreen-useragent',
901       'superfish_touchuam',
902     ]);
903
904     $this->configuration['small'] = $form_state->getValue([
905       'sf-plugins',
906       'sf-smallscreen',
907       'superfish_small',
908     ]);
909     $this->configuration['smallact'] = $form_state->getValue([
910       'sf-plugins',
911       'sf-smallscreen',
912       'superfish_smallact',
913     ]);
914     $this->configuration['smallbp'] = $form_state->getValue([
915       'sf-plugins',
916       'sf-smallscreen',
917       'sf-smallscreen-windowwidth',
918       'superfish_smallbp',
919     ]);
920     $this->configuration['smallua'] = $form_state->getValue([
921       'sf-plugins',
922       'sf-smallscreen',
923       'sf-smallscreen-useragent',
924       'superfish_smallua',
925     ]);
926     $this->configuration['smallual'] = $form_state->getValue([
927       'sf-plugins',
928       'sf-smallscreen',
929       'sf-smallscreen-useragent',
930       'superfish_smallual',
931     ]);
932     $this->configuration['smalluam'] = $form_state->getValue([
933       'sf-plugins',
934       'sf-smallscreen',
935       'sf-smallscreen-useragent',
936       'superfish_smalluam',
937     ]);
938     $this->configuration['smallset'] = $form_state->getValue([
939       'sf-plugins',
940       'sf-smallscreen',
941       'sf-smallscreen-select',
942       'superfish_smallset',
943     ]);
944     $this->configuration['smallasa'] = $form_state->getValue([
945       'sf-plugins',
946       'sf-smallscreen',
947       'sf-smallscreen-select',
948       'superfish_smallasa',
949     ]);
950     $this->configuration['smallcmc'] = $form_state->getValue([
951       'sf-plugins',
952       'sf-smallscreen',
953       'sf-smallscreen-select',
954       'sf-smallscreen-select-more',
955       'superfish_smallcmc',
956     ]);
957     $this->configuration['smallecm'] = $form_state->getValue([
958       'sf-plugins',
959       'sf-smallscreen',
960       'sf-smallscreen-select',
961       'sf-smallscreen-select-more',
962       'superfish_smallecm',
963     ]);
964     $this->configuration['smallchc'] = $form_state->getValue([
965       'sf-plugins',
966       'sf-smallscreen',
967       'sf-smallscreen-select',
968       'sf-smallscreen-select-more',
969       'superfish_smallchc',
970     ]);
971     $this->configuration['smallech'] = $form_state->getValue([
972       'sf-plugins',
973       'sf-smallscreen',
974       'sf-smallscreen-select',
975       'sf-smallscreen-select-more',
976       'superfish_smallech',
977     ]);
978     $this->configuration['smallicm'] = $form_state->getValue([
979       'sf-plugins',
980       'sf-smallscreen',
981       'sf-smallscreen-select',
982       'sf-smallscreen-select-more',
983       'superfish_smallicm',
984     ]);
985     $this->configuration['smallich'] = $form_state->getValue([
986       'sf-plugins',
987       'sf-smallscreen',
988       'sf-smallscreen-select',
989       'sf-smallscreen-select-more',
990       'superfish_smallich',
991     ]);
992     $this->configuration['smallamt'] = $form_state->getValue([
993       'sf-plugins',
994       'sf-smallscreen',
995       'sf-smallscreen-accordion',
996       'superfish_smallamt',
997     ]);
998     $this->configuration['smallabt'] = $form_state->getValue([
999       'sf-plugins',
1000       'sf-smallscreen',
1001       'sf-smallscreen-accordion',
1002       'superfish_smallabt',
1003     ]);
1004
1005     $this->configuration['supersubs'] = $form_state->getValue([
1006       'sf-plugins',
1007       'sf-supersubs',
1008       'superfish_supersubs',
1009     ]);
1010     $this->configuration['minwidth'] = $form_state->getValue([
1011       'sf-plugins',
1012       'sf-supersubs',
1013       'superfish_minwidth',
1014     ]);
1015     $this->configuration['maxwidth'] = $form_state->getValue([
1016       'sf-plugins',
1017       'sf-supersubs',
1018       'superfish_maxwidth',
1019     ]);
1020     $this->configuration['multicolumn'] = $form_state->getValue([
1021       'sf-multicolumn',
1022       'superfish_multicolumn',
1023     ]);
1024     $this->configuration['multicolumn_depth'] = $form_state->getValue([
1025       'sf-multicolumn',
1026       'superfish_multicolumn_depth',
1027     ]);
1028     $this->configuration['multicolumn_levels'] = $form_state->getValue([
1029       'sf-multicolumn',
1030       'superfish_multicolumn_levels',
1031     ]);
1032
1033     $this->configuration['speed'] = $form_state->getValue([
1034       'sf-advanced',
1035       'sf-settings',
1036       'superfish_speed',
1037     ]);
1038     $this->configuration['delay'] = $form_state->getValue([
1039       'sf-advanced',
1040       'sf-settings',
1041       'superfish_delay',
1042     ]);
1043     $this->configuration['pathlevels'] = $form_state->getValue([
1044       'sf-advanced',
1045       'sf-settings',
1046       'superfish_pathlevels',
1047     ]);
1048     $this->configuration['expanded'] = $form_state->getValue([
1049       'sf-advanced',
1050       'sf-hyperlinks',
1051       'superfish_expanded',
1052     ]);
1053     $this->configuration['clone_parent'] = $form_state->getValue([
1054       'sf-advanced',
1055       'sf-hyperlinks',
1056       'superfish_clone_parent',
1057     ]);
1058     $this->configuration['hide_linkdescription'] = $form_state->getValue([
1059       'sf-advanced',
1060       'sf-hyperlinks',
1061       'superfish_hide_linkdescription',
1062     ]);
1063     $this->configuration['add_linkdescription'] = $form_state->getValue([
1064       'sf-advanced',
1065       'sf-hyperlinks',
1066       'superfish_add_linkdescription',
1067     ]);
1068     $this->configuration['link_depth_class'] = $form_state->getValue([
1069       'sf-advanced',
1070       'sf-hyperlinks',
1071       'superfish_itemdepth',
1072     ]);
1073     $this->configuration['custom_list_class'] = $form_state->getValue([
1074       'sf-advanced',
1075       'sf-custom-classes',
1076       'superfish_ulclass',
1077     ]);
1078     $this->configuration['custom_item_class'] = $form_state->getValue([
1079       'sf-advanced',
1080       'sf-custom-classes',
1081       'superfish_liclass',
1082     ]);
1083     $this->configuration['custom_link_class'] = $form_state->getValue([
1084       'sf-advanced',
1085       'sf-custom-classes',
1086       'superfish_hlclass',
1087     ]);
1088   }
1089
1090   /**
1091    * Implements \Drupal\block\BlockBase::build().
1092    */
1093   public function build() {
1094
1095     $build = [];
1096
1097     // Block settings which will be passed to the Superfish themes.
1098     $sfsettings                         = [];
1099     $sfsettings['level']                = $this->configuration['level'];
1100     $sfsettings['depth']                = $this->configuration['depth'];
1101     $sfsettings['menu_type']            = $this->configuration['menu_type'];
1102     $sfsettings['style']                = $this->configuration['style'];
1103     $sfsettings['expanded']             = $this->configuration['expanded'];
1104     $sfsettings['itemdepth']            = $this->configuration['link_depth_class'];
1105     $sfsettings['ulclass']              = $this->configuration['custom_list_class'];
1106     $sfsettings['liclass']              = $this->configuration['custom_item_class'];
1107     $sfsettings['hlclass']              = $this->configuration['custom_link_class'];
1108     $sfsettings['clone_parent']         = $this->configuration['clone_parent'];
1109     $sfsettings['hide_linkdescription'] = $this->configuration['hide_linkdescription'];
1110     $sfsettings['add_linkdescription']  = $this->configuration['add_linkdescription'];
1111     $sfsettings['multicolumn']          = $this->configuration['multicolumn'];
1112     $sfsettings['multicolumn_depth']    = ($this->configuration['menu_type'] == 'navbar' && $this->configuration['multicolumn_depth'] == 1) ? 2 : $this->configuration['multicolumn_depth'];
1113     $sfsettings['multicolumn_levels']   = $this->configuration['multicolumn_levels'] + $sfsettings['multicolumn_depth'];
1114
1115     // jQuery plugin options which will be passed to the Drupal behavior.
1116     $sfoptions = [];
1117     $sfoptions['pathClass'] = ($sfsettings['menu_type'] == 'navbar') ? 'active-trail' : '';
1118     $sfoptions['pathLevels'] = ($this->configuration['pathlevels'] != 1) ? $this->configuration['pathlevels'] : '';
1119     $sfoptions['delay'] = ($this->configuration['delay'] != 800) ? $this->configuration['delay'] : '';
1120     $sfoptions['animation']['opacity'] = 'show';
1121     $slide = $this->configuration['slide'];
1122     if (strpos($slide, '_')) {
1123       $slide = explode('_', $slide);
1124       switch ($slide[1]) {
1125         case 'vertical':
1126           $sfoptions['animation']['height'] = ['show', $slide[0]];
1127           break;
1128
1129         case 'horizontal':
1130           $sfoptions['animation']['width'] = ['show', $slide[0]];
1131           break;
1132
1133         case 'diagonal':
1134           $sfoptions['animation']['height'] = ['show', $slide[0]];
1135           $sfoptions['animation']['width'] = ['show', $slide[0]];
1136           break;
1137
1138       }
1139       $build['#attached']['library'][] = 'superfish/superfish_easing';
1140     }
1141     else {
1142       switch ($slide) {
1143         case 'vertical':
1144           $sfoptions['animation']['height'] = 'show';
1145           break;
1146
1147         case 'horizontal':
1148           $sfoptions['animation']['width'] = 'show';
1149           break;
1150
1151         case 'diagonal':
1152           $sfoptions['animation']['height'] = 'show';
1153           $sfoptions['animation']['width'] = 'show';
1154           break;
1155
1156       }
1157     }
1158     $speed = $this->configuration['speed'];
1159     if ($speed != 'normal') {
1160       if (is_numeric($speed)) {
1161         $sfoptions['speed'] = (int) $speed;
1162       }
1163       elseif (in_array($speed, ['slow', 'normal', 'fast'])) {
1164         $sfoptions['speed'] = $speed;
1165       }
1166     }
1167     if ($this->configuration['arrow'] == 0) {
1168       $sfoptions['autoArrows'] = FALSE;
1169     }
1170     if ($this->configuration['shadow'] == 0) {
1171       $sfoptions['dropShadows'] = FALSE;
1172     }
1173
1174     if ($this->configuration['hoverintent']) {
1175       $build['#attached']['library'][] = 'superfish/superfish_hoverintent';
1176     }
1177     else {
1178       $sfoptions['disableHI'] = TRUE;
1179     }
1180     $sfoptions = sf_array_filter($sfoptions);
1181
1182     // Options for Superfish sub-plugins.
1183     $sfplugins = [];
1184     $touchscreen = $this->configuration['touch'];
1185     if ($touchscreen) {
1186       $build['#attached']['library'][] = 'superfish/superfish_touchscreen';
1187       $behaviour = $this->configuration['touchbh'];
1188       $sfplugins['touchscreen']['behaviour'] = ($behaviour != 2) ? $behaviour : '';
1189       switch ($touchscreen) {
1190         case 1:
1191           $sfplugins['touchscreen']['mode'] = 'always_active';
1192           break;
1193
1194         case 2:
1195           $sfplugins['touchscreen']['mode'] = 'window_width';
1196           $tsbp = $this->configuration['touchbp'];
1197           $sfplugins['touchscreen']['breakpoint'] = ($tsbp != 768) ? (int) $tsbp : '';
1198           break;
1199
1200         case 3:
1201           // Which method to use for UA detection.
1202           $tsuam = $this->configuration['touchuam'];
1203           $tsua = $this->configuration['touchua'];
1204           switch ($tsuam) {
1205             // Client-side.
1206             case 0:
1207               switch ($tsua) {
1208                 case 0:
1209                   $sfplugins['touchscreen']['mode'] = 'useragent_predefined';
1210                   break;
1211
1212                 case 1:
1213                   $sfplugins['touchscreen']['mode'] = 'useragent_custom';
1214                   $tsual = drupal_strtolower($this->configuration['touchual']);
1215                   if (strpos($tsual, '*')) {
1216                     $tsual = str_replace('*', '|', $tsual);
1217                   }
1218                   $sfplugins['touchscreen']['useragent'] = $tsual;
1219                   break;
1220
1221               }
1222               break;
1223
1224             // Server-side.
1225             case 1:
1226               if (isset($_SERVER['HTTP_USER_AGENT'])) {
1227                 $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
1228                 switch ($tsua) {
1229                   // Use the pre-defined list of mobile UA strings.
1230                   case 0:
1231                     if (preg_match('/(android|bb\d+|meego)|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $hua)) {
1232                       $sfplugins['touchscreen']['mode'] = 'always_active';
1233                       if ($behaviour == 2) {
1234                         $sfsettings['clone_parent'] = 1;
1235                       }
1236                     }
1237                     break;
1238
1239                   // Use the custom list of UA strings.
1240                   case 1:
1241                     $tsual = drupal_strtolower($this->configuration['touchual']);
1242                     $tsuac = [];
1243                     if (strpos($tsual, '*')) {
1244                       $tsual = explode('*', $tsual);
1245                       foreach ($tsual as $ua) {
1246                         $tsuac[] = (strpos($hua, $ua)) ? 1 : 0;
1247                       }
1248                     }
1249                     else {
1250                       $tsuac[] = (strpos($hua, $tsual)) ? 1 : 0;
1251                     }
1252                     if (in_array(1, $tsuac)) {
1253                       $sfplugins['touchscreen']['mode'] = 'always_active';
1254                       if ($behaviour == 2) {
1255                         $sfsettings['clone_parent'] = 1;
1256                       }
1257                     }
1258                     break;
1259
1260                 }
1261               }
1262               break;
1263
1264           }
1265           break;
1266
1267       }
1268     }
1269
1270     $smallscreen = $this->configuration['small'];
1271     if ($smallscreen) {
1272       $build['#attached']['library'][] = 'superfish/superfish_smallscreen';
1273       switch ($smallscreen) {
1274         case 1:
1275           $sfplugins['smallscreen']['mode'] = 'always_active';
1276           break;
1277
1278         case 2:
1279           $sfplugins['smallscreen']['mode'] = 'window_width';
1280           $ssbp = $this->configuration['smallbp'];
1281           if ($ssbp != 768) {
1282             $sfplugins['smallscreen']['breakpoint'] = (int) $ssbp;
1283           }
1284           else {
1285             $sfplugins['smallscreen']['breakpoint'] = '';
1286           }
1287           break;
1288
1289         case 3:
1290           // Which method to use for UA detection.
1291           $ssuam = $this->configuration['smalluam'];
1292           $ssua = $this->configuration['smallua'];
1293           switch ($ssuam) {
1294             // Client-side.
1295             case 0:
1296               switch ($ssua) {
1297                 case 0:
1298                   $sfplugins['smallscreen']['mode'] = 'useragent_predefined';
1299                   break;
1300
1301                 case 1:
1302                   $sfplugins['smallscreen']['mode'] = 'useragent_custom';
1303                   $ssual = drupal_strtolower($this->configuration['smallual']);
1304                   if (strpos($ssual, '*')) {
1305                     $ssual = str_replace('*', '|', $ssual);
1306                   }
1307                   $sfplugins['smallscreen']['useragent'] = $ssual;
1308                   break;
1309
1310               }
1311               break;
1312
1313             // Server-side.
1314             case 1:
1315               if (isset($_SERVER['HTTP_USER_AGENT'])) {
1316                 $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
1317                 switch ($ssua) {
1318                   // Use the pre-defined list of mobile UA strings.
1319                   case 0:
1320                     if (preg_match('/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $hua)) {
1321                       $sfplugins['smallscreen']['mode'] = 'always_active';
1322                     }
1323                     break;
1324
1325                   // Use the custom list of UA strings.
1326                   case 1:
1327                     $ssual = $this->configuration['smallual'];
1328                     $ssual = drupal_strtolower($ssual);
1329                     $ssuac = [];
1330                     if (strpos($ssual, '*')) {
1331                       $ssual = explode('*', $ssual);
1332                       foreach ($ssual as $ua) {
1333                         $ssuac[] = (strpos($hua, $ua)) ? 1 : 0;
1334                       }
1335                     }
1336                     else {
1337                       $ssuac[] = (strpos($hua, $ssual)) ? 1 : 0;
1338                     }
1339                     if (in_array(1, $ssuac)) {
1340                       $sfplugins['smallscreen']['mode'] = 'always_active';
1341                     }
1342                     break;
1343
1344                 }
1345               }
1346               break;
1347
1348           }
1349           break;
1350
1351       }
1352       $type = $this->configuration['smallact'];
1353       switch ($type) {
1354         case 0:
1355           $asa = $this->configuration['smallasa'];
1356           $cmc = $this->configuration['smallcmc'];
1357           $chc = $this->configuration['smallchc'];
1358           $ecm = $this->configuration['smallecm'];
1359           $ech = $this->configuration['smallech'];
1360           $icm = $this->configuration['smallicm'];
1361           $ich = $this->configuration['smallich'];
1362
1363           $sfplugins['smallscreen']['type'] = 'select';
1364           $sfplugins['smallscreen']['addSelected'] = ($asa == 1) ? TRUE : '';
1365           $sfplugins['smallscreen']['menuClasses'] = ($cmc == 1) ? TRUE : '';
1366           if ($chc == 1) {
1367             $sfplugins['smallscreen']['hyperlinkClasses'] = TRUE;
1368           }
1369           if ($cmc == 1 && !empty($ecm)) {
1370             $sfplugins['smallscreen']['excludeClass_menu'] = $ecm;
1371           }
1372           if ($chc == 1 && !empty($ech)) {
1373             $sfplugins['smallscreen']['excludeClass_hyperlink'] = $ech;
1374           }
1375           if (!empty($icm)) {
1376             $sfplugins['smallscreen']['includeClass_menu'] = $icm;
1377           }
1378           if (!empty($ich)) {
1379             $sfplugins['smallscreen']['includeClass_hyperlink'] = $ich;
1380           }
1381           break;
1382
1383         case 1:
1384           $ab = $this->configuration['smallabt'];
1385           $sfplugins['smallscreen']['accordionButton'] = ($ab != 1) ? $ab : '';
1386           if ($this->t('Expand') != 'Expand') {
1387             $sfplugins['smallscreen']['expandText'] = $this->t('Expand');
1388           }
1389           if ($this->t('Collapse') != 'Collapse') {
1390             $sfplugins['smallscreen']['collapseText'] = $this->t('Collapse');
1391           }
1392           break;
1393
1394       }
1395     }
1396
1397     if ($this->configuration['supposition']) {
1398       $sfplugins['supposition'] = TRUE;
1399       $build['#attached']['library'][] = 'superfish/superfish_supposition';
1400     }
1401
1402     if ($this->configuration['supersubs']) {
1403       $build['#attached']['library'][] = 'superfish/superfish_supersubs';
1404       $minwidth = $this->configuration['minwidth'];
1405       $maxwidth = $this->configuration['maxwidth'];
1406       $sfplugins['supersubs']['minWidth'] = ($minwidth != 12) ? $minwidth : '';
1407       $sfplugins['supersubs']['maxWidth'] = ($maxwidth != 27) ? $maxwidth : '';
1408       if (empty($sfplugins['supersubs']['minWidth']) &&
1409           empty($sfplugins['supersubs']['maxWidth'])) {
1410         $sfplugins['supersubs'] = TRUE;
1411       }
1412     }
1413
1414     // Attaching the requires JavaScript and CSS files.
1415     $build['#attached']['library'][] = 'superfish/superfish';
1416     if ($sfsettings['style'] != 'none') {
1417       $style = 'superfish/superfish_style_' . $sfsettings['style'];
1418       $build['#attached']['library'][] = $style;
1419     }
1420
1421     // Title for the small-screen menu.
1422     if ($smallscreen) {
1423       $title = '';
1424       switch ($type) {
1425         case 0:
1426           $title = $this->configuration['smallset'];
1427           break;
1428
1429         case 1:
1430           $title = $this->configuration['smallamt'];
1431           break;
1432
1433       }
1434       $sfplugins['smallscreen']['title'] = $title ? $title : $this->label();
1435     }
1436     $sfplugins = sf_array_filter($sfplugins);
1437
1438     // Menu block ID.
1439     $menu_name = $this->getDerivativeId();
1440
1441     // Menu tree.
1442     $level = $this->configuration['level'];
1443     // Menu display depth.
1444     $depth = $sfsettings['depth'];
1445
1446     /*
1447      * By not setting the any expanded parents we don't limit the loading of the
1448      * subtrees.
1449      * Calling MenuLinkTreeInterface::getCurrentRouteMenuTreeParameters we
1450      * would be doing so.
1451      * We don't actually need the parents expanded as we do different rendering.
1452      */
1453     if ($depth) {
1454       $maxdepth = min($level + ($depth - 1), $this->menuTree->maxDepth());
1455     }
1456     else {
1457       $maxdepth = NULL;
1458     }
1459     $parameters = (new MenuTreeParameters())
1460       ->setMinDepth($level)
1461       ->setMaxDepth($maxdepth)
1462       ->setActiveTrail($this->menuActiveTrail->getActiveTrailIds($menu_name))
1463       ->onlyEnabledLinks();
1464
1465     $tree = $this->menuTree->load($menu_name, $parameters);
1466     $manipulators = [
1467       ['callable' => 'menu.default_tree_manipulators:checkAccess'],
1468       ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
1469     ];
1470     $tree = $this->menuTree->transform($tree, $manipulators);
1471
1472     // Unique HTML ID.
1473     $id = Html::getUniqueId('superfish-' . $menu_name);
1474
1475     // Preparing the Drupal behavior.
1476     $build['#attached']['drupalSettings']['superfish'][$id]['id'] = $id;
1477     if (isset($sfoptions)) {
1478       $build['#attached']['drupalSettings']['superfish'][$id]['sf'] = $sfoptions;
1479     }
1480     else {
1481       $build['#attached']['drupalSettings']['superfish'][$id]['sf'] = [];
1482     }
1483     if (!empty($sfplugins)) {
1484       $build['#attached']['drupalSettings']['superfish'][$id]['plugins'] = $sfplugins;
1485     }
1486
1487     // Calling the theme.
1488     $build['content'] = [
1489       '#theme'  => 'superfish',
1490       '#menu_name' => $menu_name,
1491       '#html_id' => $id,
1492       '#tree' => $tree,
1493       '#settings' => $sfsettings,
1494     ];
1495     // Build the original menu tree to calculate cache tags and contexts.
1496     $treeBuild = $this->menuTree->build($tree);
1497     $build['#cache'] = $treeBuild['#cache'];
1498
1499     return $build;
1500   }
1501
1502   /**
1503    * Overrides \Drupal\block\BlockBase::defaultConfiguration().
1504    */
1505   public function defaultConfiguration() {
1506     return parent::defaultConfiguration() + [
1507       'level' => 1,
1508       'depth' => 0,
1509       'menu_type' => 'horizontal',
1510       'style' => 'none',
1511       'arrow' => 1,
1512       'shadow' => 1,
1513       'speed' => 'fast',
1514       'delay' => 800,
1515       'slide' => 'vertical',
1516       'supposition' => 1,
1517       'hoverintent' => 1,
1518       'touch' => 0,
1519       'touchbh' => 2,
1520       'touchbp' => 768,
1521       'touchua' => 0,
1522       'touchual' => '',
1523       'touchuam' => 0,
1524       'small' => 2,
1525       'smallbp' => 768,
1526       'smallua' => 0,
1527       'smallual' => '',
1528       'smalluam' => 0,
1529       'smallact' => 1,
1530       'smallset' => '',
1531       'smallasa' => 0,
1532       'smallcmc' => 0,
1533       'smallecm' => '',
1534       'smallchc' => 0,
1535       'smallech' => '',
1536       'smallicm' => '',
1537       'smallich' => '',
1538       'smallamt' => '',
1539       'smallabt' => 1,
1540       'supersubs' => 1,
1541       'minwidth' => 12,
1542       'maxwidth' => 27,
1543       'multicolumn' => 0,
1544       'multicolumn_depth' => 1,
1545       'multicolumn_levels' => 0,
1546       'pathlevels' => 1,
1547       'expanded' => 0,
1548       'clone_parent' => 0,
1549       'hide_linkdescription' => 0,
1550       'add_linkdescription' => 0,
1551       'link_depth_class' => 1,
1552       'custom_list_class' => '',
1553       'custom_item_class' => '',
1554       'custom_link_class' => '',
1555     ];
1556   }
1557
1558 }