145 lines
3.4 KiB
Plaintext
145 lines
3.4 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Main functions of the module.
|
|
*/
|
|
use Drupal\Core\Cache\CacheBackendInterface;
|
|
|
|
/**
|
|
* Implements hook_permission().
|
|
*/
|
|
function tour_permission() {
|
|
return array(
|
|
'access tour' => array(
|
|
'title' => t('Access tour'),
|
|
'description' => t('View tour tips.'),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Implements hook_library_info().
|
|
*/
|
|
function tour_library_info() {
|
|
$path = drupal_get_path('module', 'tour');
|
|
|
|
$libraries['tour'] = array(
|
|
'title' => 'Tour',
|
|
'version' => \Drupal::VERSION,
|
|
'js' => array(
|
|
$path . '/js/tour.js' => array('group' => JS_LIBRARY),
|
|
),
|
|
'dependencies' => array(
|
|
array('system', 'jquery'),
|
|
array('system', 'drupal'),
|
|
array('system', 'backbone'),
|
|
array('tour', 'jquery.joyride'),
|
|
array('tour', 'tour-styling'),
|
|
),
|
|
);
|
|
|
|
$libraries['tour-styling'] = array(
|
|
'title' => 'Tour',
|
|
'version' => \Drupal::VERSION,
|
|
'css' => array(
|
|
$path . '/css/tour.module.css' => array('media' => 'screen'),
|
|
),
|
|
);
|
|
|
|
$libraries['jquery.joyride'] = array(
|
|
'title' => 'Joyride',
|
|
'website' => 'https://github.com/zurb/joyride',
|
|
'version' => '2.0.3',
|
|
'js' => array(
|
|
$path . '/js/jquery.joyride-2.0.3.js' => array(),
|
|
),
|
|
'css' => array(
|
|
$path . '/css/joyride-2.0.3.css' => array('media' => 'screen'),
|
|
),
|
|
'dependencies' => array(
|
|
array('system', 'jquery'),
|
|
array('system', 'jquery.cookie'),
|
|
),
|
|
);
|
|
|
|
return $libraries;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_toolbar().
|
|
*/
|
|
function tour_toolbar() {
|
|
if (!\Drupal::currentUser()->hasPermission('access tour')) {
|
|
return;
|
|
}
|
|
|
|
$tab['tour'] = array(
|
|
'#type' => 'toolbar_item',
|
|
'tab' => array(
|
|
'#type' => 'html_tag',
|
|
'#tag' => 'button',
|
|
'#value' => t('Tour'),
|
|
'#attributes' => array(
|
|
'class' => array('toolbar-icon', 'toolbar-icon-help'),
|
|
'role' => 'button',
|
|
'aria-pressed' => 'false',
|
|
),
|
|
),
|
|
'#wrapper_attributes' => array(
|
|
'class' => array('tour-toolbar-tab', 'hidden'),
|
|
'id' => 'toolbar-tab-tour',
|
|
),
|
|
'#attached' => array(
|
|
'library' => array(
|
|
array('tour', 'tour'),
|
|
),
|
|
),
|
|
);
|
|
|
|
return $tab;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_preprocess_HOOK() for page templates.
|
|
*/
|
|
function tour_preprocess_page(&$variables) {
|
|
if (!\Drupal::currentUser()->hasPermission('access tour')) {
|
|
return;
|
|
}
|
|
|
|
// @todo replace this with http://drupal.org/node/1918768 once it is committed.
|
|
$path = current_path();
|
|
$tour_items = array();
|
|
// Load all of the items and match on path.
|
|
$tours = entity_load_multiple('tour');
|
|
|
|
$path_alias = drupal_strtolower(\Drupal::service('path.alias_manager')->getPathAlias($path));
|
|
foreach ($tours as $tour_id => $tour) {
|
|
// @todo Replace this with an entity query that does path matching when
|
|
// http://drupal.org/node/1918768 lands.
|
|
$pages = implode("\n", $tour->getPaths());
|
|
if (!drupal_match_path($path_alias, $pages) && (($path == $path_alias) || drupal_match_path($path, $pages))) {
|
|
unset($tours[$tour_id]);
|
|
}
|
|
}
|
|
|
|
if ($tours) {
|
|
$variables['page']['help']['tour'] = entity_view_multiple($tours, 'full');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_tour_insert().
|
|
*/
|
|
function tour_tour_insert($entity) {
|
|
\Drupal::service('plugin.manager.tour.tip')->clearCachedDefinitions();
|
|
}
|
|
|
|
/**
|
|
* Implements hook_tour_update().
|
|
*/
|
|
function tour_tour_update($entity) {
|
|
\Drupal::service('plugin.manager.tour.tip')->clearCachedDefinitions();
|
|
}
|