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