3 namespace Drupal\superfish\Plugin\Block;
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;
11 * Provides a "Superfish" block.
15 * admin_label = @Translation("Superfish"),
17 * category = @Translation("Superfish"),
18 * deriver = "Drupal\system\Plugin\Derivative\SystemMenuBlock"
21 class SuperfishBlock extends SystemMenuBlock {
24 * Overrides \Drupal\block\BlockBase::blockForm().
26 public function blockForm($form, FormStateInterface $form_state) {
27 $form = parent::blockForm($form, $form_state);
28 $defaults = $this->defaultConfiguration();
31 '#title' => $this->t('Block settings'),
34 $description = sprintf('<em>(%s: %s)</em>',
36 $this->t('Horizontal (single row)')
38 $form['sf']['superfish_type'] = [
40 '#title' => $this->t('Menu type'),
41 '#description' => $description,
42 '#default_value' => $this->configuration['menu_type'],
44 'horizontal' => $this->t('Horizontal (single row)'),
45 'navbar' => $this->t('Horizontal (double row)'),
46 'vertical' => $this->t('Vertical (stack)'),
49 $description = sprintf('<em>(%s: %s)</em>',
53 $form['sf']['superfish_style'] = [
55 '#title' => $this->t('Style'),
56 '#description' => $description,
57 '#default_value' => $this->configuration['style'],
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'),
67 $form['sf']['superfish_arrow'] = [
68 '#type' => 'checkbox',
69 '#title' => $this->t('Add arrows to parent menus'),
70 '#default_value' => $this->configuration['arrow'],
72 $form['sf']['superfish_shadow'] = [
73 '#type' => 'checkbox',
74 '#title' => $this->t('Drop shadows'),
75 '#default_value' => $this->configuration['shadow'],
77 if (count(superfish_effects()) == 4) {
78 $easing_instructions = $this->t('jQuery Easing plugin is not installed.');
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.");
83 $description = sprintf('<em>(%s: %s)</em><br>%s<br>',
88 $form['sf']['superfish_slide'] = [
90 '#title' => $this->t('Slide-in effect'),
91 '#description' => $description,
92 '#default_value' => $this->configuration['slide'],
93 '#options' => superfish_effects(),
95 $form['sf-plugins'] = [
97 '#title' => $this->t('Superfish plugins'),
100 $description = sprintf('%s <em>(%s: %s)</em>',
101 $this->t('Relocates sub-menus when they would otherwise appear outside the browser window area.'),
105 $form['sf-plugins']['superfish_supposition'] = [
106 '#type' => 'checkbox',
107 '#title' => $this->t('jQuery Supposition'),
108 '#description' => $description,
109 '#default_value' => $this->configuration['supposition'],
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>."),
116 $form['sf-plugins']['superfish_hoverintent'] = [
117 '#type' => 'checkbox',
118 '#title' => $this->t('jQuery hoverIntent'),
119 '#description' => $description,
120 '#default_value' => $this->configuration['hoverintent'],
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.')
126 $form['sf-plugins']['sf-touchscreen'] = [
127 '#type' => 'details',
128 '#title' => $this->t('sf-Touchscreen'),
129 '#description' => $description,
132 $default = sprintf('%s <em>(%s)</em>',
136 $form['sf-plugins']['sf-touchscreen']['superfish_touch'] = [
138 '#default_value' => $this->configuration['touch'],
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>."),
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.'),
150 $form['sf-plugins']['sf-touchscreen']['superfish_touchbh'] = [
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'],
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.'),
161 $description = sprintf('%s<br><br>%s<br><code><meta name="viewport" content="width=device-width, initial-scale=1.0" /></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:')
165 $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth'] = [
166 '#type' => 'details',
167 '#title' => $this->t('Window width settings'),
168 '#description' => $description,
171 $description = sprintf('%s <em>(%s: 768)</em>',
172 $this->t('Also known as "Breakpoint".'),
175 $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-windowwidth']['superfish_touchbp'] = [
177 '#description' => $description,
178 '#default_value' => $this->configuration['touchbp'],
179 '#field_suffix' => $this->t('pixels'),
182 $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent'] = [
183 '#type' => 'details',
184 '#title' => $this->t('User agent settings'),
187 $default = sprintf('%s <em>(%s) (%s)</em>',
188 $this->t('Use the pre-defined list of the <strong>user agents</strong>.'),
190 $this->t('Recommended')
192 $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchua'] = [
194 '#default_value' => $this->configuration['touchua'],
197 1 => $this->t('Use the custom list of the <strong>user agents</strong>.'),
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']
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>
216 $this->t('Could be partial or complete. (Asterisk separated)'),
219 $this->t('Examples'),
220 $this->t('Recommended'),
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'],
229 '#maxlength' => 2000,
231 $description = sprintf('<em>(%s: %s)</em>',
233 $this->t('Client-side (JavaScript)')
235 $form['sf-plugins']['sf-touchscreen']['sf-touchscreen-useragent']['superfish_touchuam'] = [
237 '#title' => $this->t('<strong>User agent</strong> detection method'),
238 '#description' => $description,
239 '#default_value' => $this->configuration['touchuam'],
241 0 => $this->t('Client-side (JavaScript)'),
242 1 => $this->t('Server-side (PHP)'),
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.'),
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>."),
255 $form['sf-plugins']['sf-smallscreen']['superfish_small'] = [
257 '#default_value' => $this->configuration['small'],
259 0 => sprintf('%s.', $this->t('Disable')),
260 1 => $this->t('Enable jQuery sf-Smallscreen plugin for this menu.'),
262 3 => $this->t("Enable jQuery sf-Smallscreen plugin for this menu depending on the user's Web browser <strong>user agent</strong>."),
265 $description = sprintf('%s<br><br>%s<br><code><meta name="viewport" content="width=device-width, initial-scale=1.0" /></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:')
269 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth'] = [
270 '#type' => 'details',
271 '#title' => $this->t('Window width settings'),
272 '#description' => $description,
275 $description = sprintf('%s <em>(%s: 768)</em>',
276 $this->t('Also known as "Breakpoint".'),
279 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-windowwidth']['superfish_smallbp'] = [
281 '#description' => $description,
282 '#default_value' => $this->configuration['smallbp'],
283 '#field_suffix' => $this->t('pixels'),
286 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent'] = [
287 '#type' => 'details',
288 '#title' => $this->t('User agent settings'),
291 $default = sprintf('%s <em>(%s) (%s)</em>',
292 $this->t('Use the pre-defined list of the <strong>user agents</strong>.'),
294 $this->t('Recommended')
296 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smallua'] = [
298 '#default_value' => $this->configuration['smallua'],
301 1 => $this->t('Use the custom list of the <strong>user agents</strong>.'),
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']
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>
320 $this->t('Could be partial or complete. (Asterisk separated)'),
323 $this->t('Examples'),
324 $this->t('Recommended'),
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'],
333 '#maxlength' => 2000,
335 $description = sprintf('<em>(%s: %s)</em>',
337 $this->t('Client-side (JavaScript)')
339 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-useragent']['superfish_smalluam'] = [
341 '#title' => $this->t('<strong>User agent</strong> detection method'),
342 '#description' => $description,
343 '#default_value' => $this->configuration['smalluam'],
345 0 => $this->t('Client-side (JavaScript)'),
346 1 => $this->t('Server-side (PHP)'),
349 $default = sprintf('%s <em>(%s)</em>',
350 $this->t('Convert the menu to an accordion menu.'),
353 $form['sf-plugins']['sf-smallscreen']['superfish_smallact'] = [
355 '#title' => $this->t('Select a type'),
356 '#default_value' => $this->configuration['smallact'],
359 0 => $this->t('Convert the menu to a <select> element.'),
362 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select'] = [
363 '#type' => 'details',
364 '#title' => $this->t('<select> settings'),
367 $description = sprintf('%s <em>(%s: %s)</em><br>%s: <em> - %s - </em>',
368 $this->t('By default the first item in the <select> element will be the name of the parent menu or the title of this block, you can change this by setting a custom title.'),
372 $this->t('Main Menu')
374 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['superfish_smallset'] = [
375 '#type' => 'textfield',
376 '#title' => $this->t('<select> title'),
377 '#description' => $description,
378 '#default_value' => $this->configuration['smallset'],
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 <option> 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'],
388 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more'] = [
389 '#type' => 'details',
390 '#title' => $this->t('More'),
393 $title = sprintf('%s <em>(%s: %s)</em>',
394 $this->t('Copy the main <ul> classes to the <select>.'),
398 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallcmc'] = [
399 '#type' => 'checkbox',
401 '#default_value' => $this->configuration['smallcmc'],
403 $description = sprintf('%s <em>(%s: %s)</em>',
404 $this->t('Comma separated'),
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 <select> element'),
411 '#description' => $description,
412 '#default_value' => $this->configuration['smallecm'],
414 '#maxlength' => 1000,
417 ':input[name="superfish_smallcmc"]' => [
424 $title = sprintf('%s <em>(%s: %s)</em>',
425 $this->t('Copy the hyperlink classes to the <option> elements of the <select>.'),
429 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-select']['sf-smallscreen-select-more']['superfish_smallchc'] = [
430 '#type' => 'checkbox',
432 '#default_value' => $this->configuration['smallchc'],
434 $description = sprintf('%s <em>(%s: %s)</em>',
435 $this->t('Comma separated'),
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 <option> elements of the <select>'),
442 '#description' => $description,
443 '#default_value' => $this->configuration['smallech'],
445 '#maxlength' => 1000,
448 ':input[name="superfish_smallchc"]' => [
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 <select> element'),
457 '#description' => $description,
458 '#default_value' => $this->configuration['smallicm'],
460 '#maxlength' => 1000,
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 <option> elements of the <select>'),
465 '#description' => $description,
466 '#default_value' => $this->configuration['smallich'],
468 '#maxlength' => 1000,
470 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-accordion'] = [
471 '#type' => 'details',
472 '#title' => $this->t('Accordion settings'),
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.'),
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'],
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.'),
494 $form['sf-plugins']['sf-smallscreen']['sf-smallscreen-accordion']['superfish_smallabt'] = [
496 '#title' => $this->t('Accordion button type'),
497 '#default_value' => $this->configuration['smallabt'],
499 0 => $this->t('Use parent menu items as buttons.'),
501 2 => $this->t('Create new links next to parent menu item links and use them as buttons.'),
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.'),
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'],
515 $description = sprintf('%s <em>(%s: 12)</em>',
516 $this->t('Minimum width for sub-menus, in <strong>em</strong> units.'),
519 $form['sf-plugins']['sf-supersubs']['superfish_minwidth'] = [
521 '#title' => $this->t('Minimum width'),
522 '#description' => $description,
523 '#default_value' => $this->configuration['minwidth'],
526 $description = sprintf('%s <em>(%s: 27)</em>',
527 $this->t('Maximum width for sub-menus, in <strong>em</strong> units.'),
530 $form['sf-plugins']['sf-supersubs']['superfish_maxwidth'] = [
532 '#title' => $this->t('Maximum width'),
533 '#description' => $description,
534 '#default_value' => $this->configuration['maxwidth'],
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'),
543 $form['sf-multicolumn']['superfish_multicolumn'] = [
544 '#type' => 'checkbox',
545 '#title' => $this->t('Enable multi-column sub-menus.'),
546 '#default_value' => $this->configuration['multicolumn'],
548 $description = sprintf('%s <em>(%s: 1)</em>',
549 $this->t('The depth of the first instance of multi-column sub-menus.'),
552 $form['sf-multicolumn']['superfish_multicolumn_depth'] = [
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)),
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.'),
563 $form['sf-multicolumn']['superfish_multicolumn_levels'] = [
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)),
570 $form['sf-advanced'] = [
571 '#type' => 'details',
572 '#title' => $this->t('Advanced settings'),
575 $form['sf-advanced']['sf-settings'] = [
576 '#type' => 'details',
577 '#title' => $this->t('Superfish'),
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>).'),
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'],
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.'),
595 $form['sf-advanced']['sf-settings']['superfish_delay'] = [
597 '#title' => $this->t('Mouse delay'),
598 '#description' => $description,
599 '#default_value' => $this->configuration['delay'],
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.'),
605 $this->t('Change this setting <strong>only and only</strong> if you are <strong>totally sure</strong> of what you are doing.')
607 $form['sf-advanced']['sf-settings']['superfish_pathlevels'] = [
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)),
614 $form['sf-advanced']['sf-hyperlinks'] = [
615 '#type' => 'details',
616 '#title' => $this->t('Hyperlinks'),
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.'),
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'],
630 $description = sprintf('%s <em>(%s: %s)</em>',
631 $this->t('Add cloned parent links to the top of sub-menus.'),
635 $form['sf-advanced']['sf-hyperlinks']['superfish_clone_parent'] = [
636 '#type' => 'checkbox',
637 '#title' => $description,
638 '#default_value' => $this->configuration['clone_parent'],
640 $description = sprintf('%s <em>(%s: %s)</em>',
641 $this->t('Disable hyperlink descriptions ("title" attribute)'),
645 $form['sf-advanced']['sf-hyperlinks']['superfish_hide_linkdescription'] = [
646 '#type' => 'checkbox',
647 '#title' => $description,
648 '#default_value' => $this->configuration['hide_linkdescription'],
650 $description = sprintf('%s <em>(%s: %s)</em>',
651 $this->t('Insert hyperlink descriptions ("title" attribute) into hyperlink texts.'),
655 $form['sf-advanced']['sf-hyperlinks']['superfish_add_linkdescription'] = [
656 '#type' => 'checkbox',
657 '#title' => $description,
658 '#default_value' => $this->configuration['add_linkdescription'],
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.'),
665 $form['sf-advanced']['sf-hyperlinks']['superfish_itemdepth'] = [
666 '#type' => 'checkbox',
668 '#default_value' => $this->configuration['link_depth_class'],
670 $form['sf-advanced']['sf-custom-classes'] = [
671 '#type' => 'details',
672 '#title' => $this->t('Custom classes'),
675 $description = sprintf('%s <em>(%s: %s)</em><br>%s: top-menu category-science',
676 $this->t('(Space separated, without dots)'),
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'],
687 '#maxlength' => 1000,
689 $description = sprintf('%s <em>(%s: %s)</em><br>%s: science-sub',
690 $this->t('(Space separated, without dots)'),
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'],
701 '#maxlength' => 1000,
703 $description = sprintf('%s <em>(%s: %s)</em><br>%s: science-link',
704 $this->t('(Space separated, without dots)'),
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'],
715 '#maxlength' => 1000,
721 * Overrides \Drupal\block\BlockBase::blockValiate().
723 public function blockValidate($form, FormStateInterface $form_state) {
724 $touch = $form_state->getValue([
727 'sf-touchscreen-useragent',
730 $touchbp = $form_state->getValue([
733 'sf-touchscreen-windowwidth',
736 $touchua = $form_state->getValue([
739 'sf-touchscreen-useragent',
742 $touchual = $form_state->getValue([
745 'sf-touchscreen-useragent',
746 'superfish_touchual',
748 $small = $form_state->getValue([
751 'sf-smallscreen-useragent',
754 $smallbp = $form_state->getValue([
757 'sf-smallscreen-windowwidth',
760 $smallua = $form_state->getValue([
763 'sf-smallscreen-useragent',
766 $smallual = $form_state->getValue([
769 'sf-smallscreen-useragent',
770 'superfish_smallual',
772 $minwidth = $form_state->getValue([
775 'superfish_minwidth',
777 $maxwidth = $form_state->getValue([
780 'superfish_maxwidth',
782 $speed = $form_state->getValue([
787 $delay = $form_state->getValue([
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.'));
796 if (!is_numeric($delay)) {
797 $form_state->setErrorByName('superfish_delay', t('Unacceptable value entered for the "Mouse delay" option.'));
799 if ($touch == 2 && $touchbp == '') {
800 $form_state->setErrorByName('superfish_touchbp', t('"sfTouchscreen Breakpoint" option cannot be empty.'));
802 if (!is_numeric($touchbp)) {
803 $form_state->setErrorByName('superfish_touchbp', t('Unacceptable value enterd for the "sfTouchscreen Breakpoint" option.'));
805 if ($touch == 3 && $touchua == 1 && $touchual == '') {
806 $form_state->setErrorByName('superfish_touchual', t('List of the touch-screen user agents cannot be empty.'));
808 if ($small == 2 && $smallbp == '') {
809 $form_state->setErrorByName('superfish_smallbp', t('"sfSmallscreen Breakpoint" option cannot be empty.'));
811 if (!is_numeric($smallbp)) {
812 $form_state->setErrorByName('superfish_smallbp', t('Unacceptable value entered for the "sfSmallscreen Breakpoint" option.'));
814 if ($small == 3 && $smallua == 1 && $smallual == '') {
815 $form_state->setErrorByName('superfish_smallual', t('List of the small-screen user agents cannot be empty.'));
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;
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;
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".'));
833 * Overrides \Drupal\block\BlockBase::blockSubmit().
835 public function blockSubmit($form, FormStateInterface $form_state) {
837 $this->configuration['level'] = $form_state->getValue('level');
838 $this->configuration['depth'] = $form_state->getValue('depth');
839 $this->configuration['menu_type'] = $form_state->getValue([
843 $this->configuration['style'] = $form_state->getValue([
847 $this->configuration['arrow'] = $form_state->getValue([
851 $this->configuration['shadow'] = $form_state->getValue([
855 $this->configuration['slide'] = $form_state->getValue([
860 $this->configuration['supposition'] = $form_state->getValue([
862 'superfish_supposition',
864 $this->configuration['hoverintent'] = $form_state->getValue([
866 'superfish_hoverintent',
869 $this->configuration['touch'] = $form_state->getValue([
874 $this->configuration['touchbh'] = $form_state->getValue([
879 $this->configuration['touchbp'] = $form_state->getValue([
882 'sf-touchscreen-windowwidth',
885 $this->configuration['touchua'] = $form_state->getValue([
888 'sf-touchscreen-useragent',
891 $this->configuration['touchual'] = $form_state->getValue([
894 'sf-touchscreen-useragent',
895 'superfish_touchual',
897 $this->configuration['touchuam'] = $form_state->getValue([
900 'sf-touchscreen-useragent',
901 'superfish_touchuam',
904 $this->configuration['small'] = $form_state->getValue([
909 $this->configuration['smallact'] = $form_state->getValue([
912 'superfish_smallact',
914 $this->configuration['smallbp'] = $form_state->getValue([
917 'sf-smallscreen-windowwidth',
920 $this->configuration['smallua'] = $form_state->getValue([
923 'sf-smallscreen-useragent',
926 $this->configuration['smallual'] = $form_state->getValue([
929 'sf-smallscreen-useragent',
930 'superfish_smallual',
932 $this->configuration['smalluam'] = $form_state->getValue([
935 'sf-smallscreen-useragent',
936 'superfish_smalluam',
938 $this->configuration['smallset'] = $form_state->getValue([
941 'sf-smallscreen-select',
942 'superfish_smallset',
944 $this->configuration['smallasa'] = $form_state->getValue([
947 'sf-smallscreen-select',
948 'superfish_smallasa',
950 $this->configuration['smallcmc'] = $form_state->getValue([
953 'sf-smallscreen-select',
954 'sf-smallscreen-select-more',
955 'superfish_smallcmc',
957 $this->configuration['smallecm'] = $form_state->getValue([
960 'sf-smallscreen-select',
961 'sf-smallscreen-select-more',
962 'superfish_smallecm',
964 $this->configuration['smallchc'] = $form_state->getValue([
967 'sf-smallscreen-select',
968 'sf-smallscreen-select-more',
969 'superfish_smallchc',
971 $this->configuration['smallech'] = $form_state->getValue([
974 'sf-smallscreen-select',
975 'sf-smallscreen-select-more',
976 'superfish_smallech',
978 $this->configuration['smallicm'] = $form_state->getValue([
981 'sf-smallscreen-select',
982 'sf-smallscreen-select-more',
983 'superfish_smallicm',
985 $this->configuration['smallich'] = $form_state->getValue([
988 'sf-smallscreen-select',
989 'sf-smallscreen-select-more',
990 'superfish_smallich',
992 $this->configuration['smallamt'] = $form_state->getValue([
995 'sf-smallscreen-accordion',
996 'superfish_smallamt',
998 $this->configuration['smallabt'] = $form_state->getValue([
1001 'sf-smallscreen-accordion',
1002 'superfish_smallabt',
1005 $this->configuration['supersubs'] = $form_state->getValue([
1008 'superfish_supersubs',
1010 $this->configuration['minwidth'] = $form_state->getValue([
1013 'superfish_minwidth',
1015 $this->configuration['maxwidth'] = $form_state->getValue([
1018 'superfish_maxwidth',
1020 $this->configuration['multicolumn'] = $form_state->getValue([
1022 'superfish_multicolumn',
1024 $this->configuration['multicolumn_depth'] = $form_state->getValue([
1026 'superfish_multicolumn_depth',
1028 $this->configuration['multicolumn_levels'] = $form_state->getValue([
1030 'superfish_multicolumn_levels',
1033 $this->configuration['speed'] = $form_state->getValue([
1038 $this->configuration['delay'] = $form_state->getValue([
1043 $this->configuration['pathlevels'] = $form_state->getValue([
1046 'superfish_pathlevels',
1048 $this->configuration['expanded'] = $form_state->getValue([
1051 'superfish_expanded',
1053 $this->configuration['clone_parent'] = $form_state->getValue([
1056 'superfish_clone_parent',
1058 $this->configuration['hide_linkdescription'] = $form_state->getValue([
1061 'superfish_hide_linkdescription',
1063 $this->configuration['add_linkdescription'] = $form_state->getValue([
1066 'superfish_add_linkdescription',
1068 $this->configuration['link_depth_class'] = $form_state->getValue([
1071 'superfish_itemdepth',
1073 $this->configuration['custom_list_class'] = $form_state->getValue([
1075 'sf-custom-classes',
1076 'superfish_ulclass',
1078 $this->configuration['custom_item_class'] = $form_state->getValue([
1080 'sf-custom-classes',
1081 'superfish_liclass',
1083 $this->configuration['custom_link_class'] = $form_state->getValue([
1085 'sf-custom-classes',
1086 'superfish_hlclass',
1091 * Implements \Drupal\block\BlockBase::build().
1093 public function build() {
1097 // Block settings which will be passed to the Superfish themes.
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'];
1115 // jQuery plugin options which will be passed to the Drupal behavior.
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]) {
1126 $sfoptions['animation']['height'] = ['show', $slide[0]];
1130 $sfoptions['animation']['width'] = ['show', $slide[0]];
1134 $sfoptions['animation']['height'] = ['show', $slide[0]];
1135 $sfoptions['animation']['width'] = ['show', $slide[0]];
1139 $build['#attached']['library'][] = 'superfish/superfish_easing';
1144 $sfoptions['animation']['height'] = 'show';
1148 $sfoptions['animation']['width'] = 'show';
1152 $sfoptions['animation']['height'] = 'show';
1153 $sfoptions['animation']['width'] = 'show';
1158 $speed = $this->configuration['speed'];
1159 if ($speed != 'normal') {
1160 if (is_numeric($speed)) {
1161 $sfoptions['speed'] = (int) $speed;
1163 elseif (in_array($speed, ['slow', 'normal', 'fast'])) {
1164 $sfoptions['speed'] = $speed;
1167 if ($this->configuration['arrow'] == 0) {
1168 $sfoptions['autoArrows'] = FALSE;
1170 if ($this->configuration['shadow'] == 0) {
1171 $sfoptions['dropShadows'] = FALSE;
1174 if ($this->configuration['hoverintent']) {
1175 $build['#attached']['library'][] = 'superfish/superfish_hoverintent';
1178 $sfoptions['disableHI'] = TRUE;
1180 $sfoptions = sf_array_filter($sfoptions);
1182 // Options for Superfish sub-plugins.
1184 $touchscreen = $this->configuration['touch'];
1186 $build['#attached']['library'][] = 'superfish/superfish_touchscreen';
1187 $behaviour = $this->configuration['touchbh'];
1188 $sfplugins['touchscreen']['behaviour'] = ($behaviour != 2) ? $behaviour : '';
1189 switch ($touchscreen) {
1191 $sfplugins['touchscreen']['mode'] = 'always_active';
1195 $sfplugins['touchscreen']['mode'] = 'window_width';
1196 $tsbp = $this->configuration['touchbp'];
1197 $sfplugins['touchscreen']['breakpoint'] = ($tsbp != 768) ? (int) $tsbp : '';
1201 // Which method to use for UA detection.
1202 $tsuam = $this->configuration['touchuam'];
1203 $tsua = $this->configuration['touchua'];
1209 $sfplugins['touchscreen']['mode'] = 'useragent_predefined';
1213 $sfplugins['touchscreen']['mode'] = 'useragent_custom';
1214 $tsual = drupal_strtolower($this->configuration['touchual']);
1215 if (strpos($tsual, '*')) {
1216 $tsual = str_replace('*', '|', $tsual);
1218 $sfplugins['touchscreen']['useragent'] = $tsual;
1226 if (isset($_SERVER['HTTP_USER_AGENT'])) {
1227 $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
1229 // Use the pre-defined list of mobile UA strings.
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;
1239 // Use the custom list of UA strings.
1241 $tsual = drupal_strtolower($this->configuration['touchual']);
1243 if (strpos($tsual, '*')) {
1244 $tsual = explode('*', $tsual);
1245 foreach ($tsual as $ua) {
1246 $tsuac[] = (strpos($hua, $ua)) ? 1 : 0;
1250 $tsuac[] = (strpos($hua, $tsual)) ? 1 : 0;
1252 if (in_array(1, $tsuac)) {
1253 $sfplugins['touchscreen']['mode'] = 'always_active';
1254 if ($behaviour == 2) {
1255 $sfsettings['clone_parent'] = 1;
1270 $smallscreen = $this->configuration['small'];
1272 $build['#attached']['library'][] = 'superfish/superfish_smallscreen';
1273 switch ($smallscreen) {
1275 $sfplugins['smallscreen']['mode'] = 'always_active';
1279 $sfplugins['smallscreen']['mode'] = 'window_width';
1280 $ssbp = $this->configuration['smallbp'];
1282 $sfplugins['smallscreen']['breakpoint'] = (int) $ssbp;
1285 $sfplugins['smallscreen']['breakpoint'] = '';
1290 // Which method to use for UA detection.
1291 $ssuam = $this->configuration['smalluam'];
1292 $ssua = $this->configuration['smallua'];
1298 $sfplugins['smallscreen']['mode'] = 'useragent_predefined';
1302 $sfplugins['smallscreen']['mode'] = 'useragent_custom';
1303 $ssual = drupal_strtolower($this->configuration['smallual']);
1304 if (strpos($ssual, '*')) {
1305 $ssual = str_replace('*', '|', $ssual);
1307 $sfplugins['smallscreen']['useragent'] = $ssual;
1315 if (isset($_SERVER['HTTP_USER_AGENT'])) {
1316 $hua = drupal_strtolower($_SERVER['HTTP_USER_AGENT']);
1318 // Use the pre-defined list of mobile UA strings.
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';
1325 // Use the custom list of UA strings.
1327 $ssual = $this->configuration['smallual'];
1328 $ssual = drupal_strtolower($ssual);
1330 if (strpos($ssual, '*')) {
1331 $ssual = explode('*', $ssual);
1332 foreach ($ssual as $ua) {
1333 $ssuac[] = (strpos($hua, $ua)) ? 1 : 0;
1337 $ssuac[] = (strpos($hua, $ssual)) ? 1 : 0;
1339 if (in_array(1, $ssuac)) {
1340 $sfplugins['smallscreen']['mode'] = 'always_active';
1352 $type = $this->configuration['smallact'];
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'];
1363 $sfplugins['smallscreen']['type'] = 'select';
1364 $sfplugins['smallscreen']['addSelected'] = ($asa == 1) ? TRUE : '';
1365 $sfplugins['smallscreen']['menuClasses'] = ($cmc == 1) ? TRUE : '';
1367 $sfplugins['smallscreen']['hyperlinkClasses'] = TRUE;
1369 if ($cmc == 1 && !empty($ecm)) {
1370 $sfplugins['smallscreen']['excludeClass_menu'] = $ecm;
1372 if ($chc == 1 && !empty($ech)) {
1373 $sfplugins['smallscreen']['excludeClass_hyperlink'] = $ech;
1376 $sfplugins['smallscreen']['includeClass_menu'] = $icm;
1379 $sfplugins['smallscreen']['includeClass_hyperlink'] = $ich;
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');
1389 if ($this->t('Collapse') != 'Collapse') {
1390 $sfplugins['smallscreen']['collapseText'] = $this->t('Collapse');
1397 if ($this->configuration['supposition']) {
1398 $sfplugins['supposition'] = TRUE;
1399 $build['#attached']['library'][] = 'superfish/superfish_supposition';
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;
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;
1421 // Title for the small-screen menu.
1426 $title = $this->configuration['smallset'];
1430 $title = $this->configuration['smallamt'];
1434 $sfplugins['smallscreen']['title'] = $title ? $title : $this->label();
1436 $sfplugins = sf_array_filter($sfplugins);
1439 $menu_name = $this->getDerivativeId();
1442 $level = $this->configuration['level'];
1443 // Menu display depth.
1444 $depth = $sfsettings['depth'];
1447 * By not setting the any expanded parents we don't limit the loading of the
1449 * Calling MenuLinkTreeInterface::getCurrentRouteMenuTreeParameters we
1450 * would be doing so.
1451 * We don't actually need the parents expanded as we do different rendering.
1454 $maxdepth = min($level + ($depth - 1), $this->menuTree->maxDepth());
1459 $parameters = (new MenuTreeParameters())
1460 ->setMinDepth($level)
1461 ->setMaxDepth($maxdepth)
1462 ->setActiveTrail($this->menuActiveTrail->getActiveTrailIds($menu_name))
1463 ->onlyEnabledLinks();
1465 $tree = $this->menuTree->load($menu_name, $parameters);
1467 ['callable' => 'menu.default_tree_manipulators:checkAccess'],
1468 ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
1470 $tree = $this->menuTree->transform($tree, $manipulators);
1473 $id = Html::getUniqueId('superfish-' . $menu_name);
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;
1481 $build['#attached']['drupalSettings']['superfish'][$id]['sf'] = [];
1483 if (!empty($sfplugins)) {
1484 $build['#attached']['drupalSettings']['superfish'][$id]['plugins'] = $sfplugins;
1487 // Calling the theme.
1488 $build['content'] = [
1489 '#theme' => 'superfish',
1490 '#menu_name' => $menu_name,
1493 '#settings' => $sfsettings,
1495 // Build the original menu tree to calculate cache tags and contexts.
1496 $treeBuild = $this->menuTree->build($tree);
1497 $build['#cache'] = $treeBuild['#cache'];
1503 * Overrides \Drupal\block\BlockBase::defaultConfiguration().
1505 public function defaultConfiguration() {
1506 return parent::defaultConfiguration() + [
1509 'menu_type' => 'horizontal',
1515 'slide' => 'vertical',
1544 'multicolumn_depth' => 1,
1545 'multicolumn_levels' => 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' => '',