5 * The jQuery Superfish plugin for Drupal menus.
8 use Drupal\Core\Block\BlockPluginInterface;
9 use Drupal\Core\Routing\RouteMatchInterface;
12 * Implements hook_block_view_BASE_BLOCK_ID_alter().
14 function superfish_block_view_superfish_alter(array &$build, BlockPluginInterface $block) {
15 $menu_name = $block->getDerivativeId();
16 $build['#contextual_links']['menu'] = [
17 'route_parameters' => ['menu' => $menu_name],
22 * Implements hook_libraries_info().
24 function superfish_libraries_info() {
25 $libraries['superfish'] = [
26 'name' => 'superfish',
27 'vendor url' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
28 'download url' => 'https://github.com/mehrpadin/Superfish-for-Drupal/zipball/2.x',
29 'version callback' => 'superfish_library_version',
33 'jquery.hoverIntent.minified.js',
41 'style/black/black.css',
42 'style/blue/blue.css',
43 'style/coffee/coffee.css',
44 'style/default/default.css',
45 'style/white/white.css',
53 * Implements hook_library_info_build().
55 function superfish_library_info_build() {
57 if ($superfish_library_path = superfish_library_path()) {
58 $superfish_library_path = '/' . $superfish_library_path;
61 'remote' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
65 'gpl-compatible' => FALSE,
68 'js/superfish.js' => [],
73 'core/drupalSettings',
79 $superfish_library_path . '/superfish.js' => [],
83 $superfish_library_path . '/css/superfish.css' => [],
87 'superfish_hoverintent' => [
89 $superfish_library_path . '/jquery.hoverIntent.minified.js' => [
97 'superfish_smallscreen' => [
99 $superfish_library_path . '/sfsmallscreen.js' => [],
105 'superfish_touchscreen' => [
107 $superfish_library_path . '/sftouchscreen.js' => [],
113 'superfish_supersubs' => [
115 $superfish_library_path . '/supersubs.js' => [],
121 'superfish_supposition' => [
123 $superfish_library_path . '/supposition.js' => [],
129 'superfish_style_black' => [
132 $superfish_library_path . '/style/black/black.css' => [],
139 'superfish_style_blue' => [
142 $superfish_library_path . '/style/blue/blue.css' => [],
149 'superfish_style_coffee' => [
152 $superfish_library_path . '/style/coffee/coffee.css' => [],
159 'superfish_style_default' => [
162 $superfish_library_path . '/style/default/default.css' => [],
169 'superfish_style_white' => [
172 $superfish_library_path . '/style/white/white.css' => [],
180 if ($easing_library_path = superfish_library_path('easing')) {
181 $easing_library_path = '/' . $easing_library_path;
183 'superfish_easing' => [
185 $easing_library_path . '/jquery.easing.js' => [],
195 * Returns the Superfish library folder location.
197 function superfish_library_path($library = 'superfish') {
199 // Ensure the Libraries API module is installed and working.
200 if (function_exists('libraries_get_path') && ($directory = libraries_get_path($library))) {
203 // Otherwise use the default directory.
204 if (file_exists('profiles/' . drupal_get_profile() . '/libraries/' . $library)) {
205 $directory = 'profiles/' . drupal_get_profile() . '/libraries/' . $library;
207 elseif (file_exists('libraries/' . $library)) {
208 $directory = 'libraries/' . $library;
210 elseif (file_exists('sites/all/libraries/' . $library)) {
211 $directory = 'sites/all/libraries/' . $library;
213 elseif (file_exists('sites/default/libraries/' . $library)) {
214 $directory = 'sites/default/libraries/' . $library;
220 * Verifies Superfish library is present.
222 function superfish_library_check() {
223 if (function_exists('libraries_get_libraries')) {
224 $library = libraries_get_libraries();
225 if (isset($library['superfish'])) {
229 elseif (($directory = superfish_library_path()) && file_exists($directory . '/superfish.js')) {
236 * Checks Superfish library version.
238 function superfish_library_version() {
239 // Get the library version.
240 if (($directory = superfish_library_path()) && file_exists($directory . '/VERSION')) {
241 $version = file_get_contents($directory . '/VERSION');
242 // Removing blank lines and white spaces.
243 $version = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", trim($version));
244 if (!empty($version)) {
253 * Generate a list of available slide-in effects.
255 function superfish_effects() {
257 'none' => '- ' . t('None') . ' -',
258 'vertical' => t('Vertical'),
259 'horizontal' => t('Horizontal'),
260 'diagonal' => t('Diagonal'),
263 if (superfish_library_path('easing')) {
265 'easeInSine_vertical' => 'easeInSine (' . t('Vertical') . ')',
266 'easeInSine_horizontal' => 'easeInSine (' . t('Horizontal') . ')',
267 'easeInSine_diagonal' => 'easeInSine (' . t('Diagonal') . ')',
268 'easeInQuint_vertical' => 'easeInQuint (' . t('Vertical') . ')',
269 'easeInQuint_horizontal' => 'easeInQuint (' . t('Horizontal') . ')',
270 'easeInQuint_diagonal' => 'easeInQuint (' . t('Diagonal') . ')',
271 'easeInQuart_vertical' => 'easeInQuart (' . t('Vertical') . ')',
272 'easeInQuart_horizontal' => 'easeInQuart (' . t('Horizontal') . ')',
273 'easeInQuart_diagonal' => 'easeInQuart (' . t('Diagonal') . ')',
274 'easeInQuad_vertical' => 'easeInQuad (' . t('Vertical') . ')',
275 'easeInQuad_horizontal' => 'easeInQuad (' . t('Horizontal') . ')',
276 'easeInQuad_diagonal' => 'easeInQuad (' . t('Diagonal') . ')',
277 'easeInExpo_vertical' => 'easeInExpo (' . t('Vertical') . ')',
278 'easeInExpo_horizontal' => 'easeInExpo (' . t('Horizontal') . ')',
279 'easeInExpo_diagonal' => 'easeInExpo (' . t('Diagonal') . ')',
280 'easeInElastic_vertical' => 'easeInElastic (' . t('Vertical') . ')',
281 'easeInElastic_horizontal' => 'easeInElastic (' . t('Horizontal') . ')',
282 'easeInElastic_diagonal' => 'easeInElastic (' . t('Diagonal') . ')',
283 'easeInCubic_vertical' => 'easeInCubic (' . t('Vertical') . ')',
284 'easeInCubic_horizontal' => 'easeInCubic (' . t('Horizontal') . ')',
285 'easeInCubic_diagonal' => 'easeInCubic (' . t('Diagonal') . ')',
286 'easeInCirc_vertical' => 'easeInCirc (' . t('Vertical') . ')',
287 'easeInCirc_horizontal' => 'easeInCirc (' . t('Horizontal') . ')',
288 'easeInCirc_diagonal' => 'easeInCirc (' . t('Diagonal') . ')',
289 'easeInBounce_vertical' => 'easeInBounce (' . t('Vertical') . ')',
290 'easeInBounce_horizontal' => 'easeInBounce (' . t('Horizontal') . ')',
291 'easeInBounce_diagonal' => 'easeInBounce (' . t('Diagonal') . ')',
292 'easeInBack_vertical' => 'easeInBack (' . t('Vertical') . ')',
293 'easeInBack_horizontal' => 'easeInBack (' . t('Horizontal') . ')',
294 'easeInBack_diagonal' => 'easeInBack (' . t('Diagonal') . ')',
296 $output = array_merge($output, $easing_types);
302 * Helper function to clean up arrays.
304 function sf_array_filter($haystack) {
305 foreach ($haystack as $key => $value) {
306 if (is_array($value)) {
307 $haystack[$key] = sf_array_filter($haystack[$key]);
309 elseif (empty($value) && is_bool($value) !== TRUE) {
310 if ($haystack[$key] != '0') {
311 unset($haystack[$key]);
319 * Implements hook_theme().
321 function superfish_theme($existing, $type, $theme, $path) {
324 'render element' => 'element',
325 'file' => 'superfish.theme.inc',
327 'superfish_menu_items' => [
328 'render element' => 'element',
329 'file' => 'superfish.theme.inc',
331 'superfish_help' => [
336 'template' => 'superfish--help',
342 * Implements hook_help().
344 function superfish_help($route_name, RouteMatchInterface $route_match) {
345 switch ($route_name) {
346 case 'help.page.superfish':
348 '#theme' => 'superfish_help',
349 '#title' => t('About Superfish'),
350 '#content' => t('<a href="@url_module">Superfish module</a> integrates <a href="@url_library">jQuery Superfish</a> plugin to your Drupal menu blocks. Please refer to the module <a href="@url_documentation">documentation</a> for more information.',
352 '@url_library' => 'https://github.com/mehrpadin/Superfish-for-Drupal',
353 '@url_module' => 'https://www.drupal.org/project/superfish',
354 '@url_documentation' => 'https://www.drupal.org/node/1125896',