5 * jQuery Superfish plugin for Drupal menus.
8 use Drupal\Component\Utility\Unicode;
9 use Drupal\Core\Block\BlockPluginInterface;
10 use Drupal\Component\Utility\SafeMarkup;
11 use Drupal\Core\Routing\RouteMatchInterface;
14 * Implements hook_block_view_BASE_BLOCK_ID_alter().
16 function superfish_block_view_superfish_alter(array &$build, BlockPluginInterface $block) {
17 $menu_name = $block->getDerivativeId();
18 $build['#contextual_links']['menu'] = array(
19 'route_parameters' => array('menu' => $menu_name),
24 * Implements hook_libraries_info().
26 function superfish_libraries_info() {
27 $libraries['superfish'] = array(
28 'name' => 'superfish',
29 'vendor url' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
30 'download url' => 'https://github.com/mehrpadin/Superfish-for-Drupal/zipball/2.x',
31 'version callback' => 'superfish_library_version',
35 'jquery.hoverIntent.minified.js',
43 'style/black/black.css',
44 'style/blue/blue.css',
45 'style/coffee/coffee.css',
46 'style/default/default.css',
47 'style/white/white.css'
55 * Implements hook_library_info_build().
57 function superfish_library_info_build() {
59 if ($superfish_library_path = superfish_library_path()) {
60 $superfish_library_path = '/' . $superfish_library_path;
63 'remote' => 'http://github.com/mehrpadin/Superfish-for-Drupal',
67 'gpl-compatible' => false,
70 'js/superfish.js' => [],
75 'core/drupalSettings',
81 $superfish_library_path . '/superfish.js' => [],
85 $superfish_library_path . '/css/superfish.css' => [],
89 'superfish_hoverintent' => [
91 $superfish_library_path . '/jquery.hoverIntent.minified.js' => [
99 'superfish_smallscreen' => [
101 $superfish_library_path . '/sfsmallscreen.js' => [],
107 'superfish_touchscreen' => [
109 $superfish_library_path . '/sftouchscreen.js' => [],
115 'superfish_supersubs' => [
117 $superfish_library_path . '/supersubs.js' => [],
123 'superfish_supposition' => [
125 $superfish_library_path . '/supposition.js' => [],
131 'superfish_style_black' => [
134 $superfish_library_path . '/style/black/black.css' => [],
141 'superfish_style_blue' => [
144 $superfish_library_path . '/style/blue/blue.css' => [],
151 'superfish_style_coffee' => [
154 $superfish_library_path . '/style/coffee/coffee.css' => [],
161 'superfish_style_default' => [
164 $superfish_library_path . '/style/default/default.css' => [],
171 'superfish_style_white' => [
174 $superfish_library_path . '/style/white/white.css' => []
182 if ($easing_library_path = superfish_library_path('easing')) {
183 $easing_library_path = '/' . $easing_library_path;
185 'superfish_easing' => [
187 $easing_library_path . '/jquery.easing.js' => [],
197 * Returns the Superfish library folder location.
199 function superfish_library_path($library = 'superfish') {
201 // Ensure the Libraries API module is installed and working.
202 if (function_exists('libraries_get_path') && ($directory = libraries_get_path($library))) {
205 // Otherwise use the default directory.
206 if (file_exists('profiles/' . drupal_get_profile() . '/libraries/' . $library)) {
207 $directory = 'profiles/' . drupal_get_profile() . '/libraries/' . $library;
209 elseif (file_exists('libraries/' . $library)) {
210 $directory = 'libraries/' . $library;
212 elseif (file_exists('sites/all/libraries/' . $library)) {
213 $directory = 'sites/all/libraries/' . $library;
219 * Verifies Superfish library is present.
221 function superfish_library_check() {
222 if (function_exists('libraries_get_libraries')) {
223 $library = libraries_get_libraries();
224 if (isset($library['superfish'])) {
228 elseif (($directory = superfish_library_path()) && file_exists($directory . '/superfish.js')) {
235 * Checks Superfish library version.
237 function superfish_library_version() {
238 // Get the library version.
239 if (($directory = superfish_library_path()) && file_exists($directory . '/VERSION')) {
240 $version = file_get_contents($directory . '/VERSION');
241 // Removing blank lines and white spaces.
242 $version = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", trim($version));
243 if (!empty($version)) {
252 * Generate a list of available slide-in effects.
254 function superfish_effects() {
256 'none' => '- ' . t('None') . ' -',
257 'vertical' => t('Vertical'),
258 'horizontal' => t('Horizontal'),
259 'diagonal' => t('Diagonal')
262 if (superfish_library_path('easing')) {
263 $easing_types = array(
264 'easeInSine_vertical' => 'easeInSine (' . t('Vertical') . ')',
265 'easeInSine_horizontal' => 'easeInSine (' . t('Horizontal') . ')',
266 'easeInSine_diagonal' => 'easeInSine (' . t('Diagonal') . ')',
267 'easeInQuint_vertical' => 'easeInQuint (' . t('Vertical') . ')',
268 'easeInQuint_horizontal' => 'easeInQuint (' . t('Horizontal') . ')',
269 'easeInQuint_diagonal' => 'easeInQuint (' . t('Diagonal') . ')',
270 'easeInQuart_vertical' => 'easeInQuart (' . t('Vertical') . ')',
271 'easeInQuart_horizontal' => 'easeInQuart (' . t('Horizontal') . ')',
272 'easeInQuart_diagonal' => 'easeInQuart (' . t('Diagonal') . ')',
273 'easeInQuad_vertical' => 'easeInQuad (' . t('Vertical') . ')',
274 'easeInQuad_horizontal' => 'easeInQuad (' . t('Horizontal') . ')',
275 'easeInQuad_diagonal' => 'easeInQuad (' . t('Diagonal') . ')',
276 'easeInExpo_vertical' => 'easeInExpo (' . t('Vertical') . ')',
277 'easeInExpo_horizontal' => 'easeInExpo (' . t('Horizontal') . ')',
278 'easeInExpo_diagonal' => 'easeInExpo (' . t('Diagonal') . ')',
279 'easeInElastic_vertical' => 'easeInElastic (' . t('Vertical') . ')',
280 'easeInElastic_horizontal' => 'easeInElastic (' . t('Horizontal') . ')',
281 'easeInElastic_diagonal' => 'easeInElastic (' . t('Diagonal') . ')',
282 'easeInCubic_vertical' => 'easeInCubic (' . t('Vertical') . ')',
283 'easeInCubic_horizontal' => 'easeInCubic (' . t('Horizontal') . ')',
284 'easeInCubic_diagonal' => 'easeInCubic (' . t('Diagonal') . ')',
285 'easeInCirc_vertical' => 'easeInCirc (' . t('Vertical') . ')',
286 'easeInCirc_horizontal' => 'easeInCirc (' . t('Horizontal') . ')',
287 'easeInCirc_diagonal' => 'easeInCirc (' . t('Diagonal') . ')',
288 'easeInBounce_vertical' => 'easeInBounce (' . t('Vertical') . ')',
289 'easeInBounce_horizontal' => 'easeInBounce (' . t('Horizontal') . ')',
290 'easeInBounce_diagonal' => 'easeInBounce (' . t('Diagonal') . ')',
291 'easeInBack_vertical' => 'easeInBack (' . t('Vertical') . ')',
292 'easeInBack_horizontal' => 'easeInBack (' . t('Horizontal') . ')',
293 'easeInBack_diagonal' => 'easeInBack (' . t('Diagonal') . ')'
295 $output = array_merge($output, $easing_types);
301 * Helper function to clean up arrays.
303 function superfish_array_remove_empty($haystack) {
304 foreach ($haystack as $key => $value) {
305 if (is_array($value)) {
306 $haystack[$key] = superfish_array_remove_empty($haystack[$key]);
308 elseif (empty($value) && is_bool($value) !== TRUE) {
309 if ($haystack[$key] != '0') {
310 unset($haystack[$key]);
318 * Implements hook_theme().
320 function superfish_theme($existing, $type, $theme, $path) {
322 'superfish' => array(
323 'render element' => 'element',
324 'file' => 'superfish.theme.inc',
326 'superfish_menu_items' => array(
327 'render element' => 'element',
328 'file' => 'superfish.theme.inc',
330 'superfish_help' => array(
331 'variables' => array(
335 'template' => 'superfish--help',
341 * Implements hook_help().
343 function superfish_help($route_name, RouteMatchInterface $route_match) {
344 switch ($route_name) {
345 case 'help.page.superfish':
347 '#theme' => 'superfish_help',
348 '#title' => t('About Superfish'),
349 '#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.',
351 '@url_library' => 'https://github.com/mehrpadin/Superfish-for-Drupal',
352 '@url_module' => 'https://www.drupal.org/project/superfish',
353 '@url_documentation' => 'https://www.drupal.org/node/1125896'