Repository URL to install this package:
|
Version:
2.0.0 ▾
|
drupal/melt_sticky_drawer
/
melt_sticky_drawer.module
|
|---|
<?php
/**
* @file
* Contains melt_sticky_drawer.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function melt_sticky_drawer_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the melt_sticky_drawer module.
case 'help.page.melt_sticky_drawer':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Creates a sticky footer until element is scrolled into view') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function melt_sticky_drawer_theme() {
return [
'melt_sticky_drawer' => [
'render element' => 'children',
],
];
}
/**
* Implements hook_page_attachments().
*/
function melt_sticky_drawer_page_attachments(&$attachments) {
// Exit if we're on an admin route.
if (\Drupal::service('router.admin_context')->isAdminRoute()) {
return FALSE;
}
$config = \Drupal::config('melt_sticky_drawer.stickydrawer');
$manager = \Drupal::service('plugin.manager.condition');
$condition = $manager->createInstance('request_path');
$condition->setConfiguration($config->get('request_path'));
// Pass JS related files to front end if the Page restrictions
// text area is empty or has paths which we'll treat as those
// we don't want JS to run on.
if (empty($config->get('request_path')['pages']) || $condition->evaluate()) {
$attachments['#attached']['drupalSettings']['meltStickyDrawer'] = [
'target' => $config->get('target_selector'),
'targetWrapper' => $config->get('target_wrapper_selector'),
'toggle' => $config->get('toggle_selector'),
'toggleAction' => $config->get('toggle_action'),
'scrollToContainer' => $config->get('scrollToContainer_selector'),
'scrollToOffset' => $config->get('scrollTo_yoffset'),
];
$attachments['#attached']['library'][] = 'melt_sticky_drawer/stickydrawer';
}
}