isAdminRoute()){
$build['#attached']['library'][] = 'user_preferences/user-preferences';
}
}
/**
* Implements hook_theme().
*/
function user_preferences_theme($existing, $type, $theme, $path) {
return array(
'user_preferences' => array(
'variables' => array(),
),
);
}
/**
* Template preprocess function for User Preferences.
*
* @param array $variables
* An associative array containing:
*/
function user_template_preprocess_preferences(&$variables) {
}
/**
* Implements hook_node_links_alter().
*/
function user_preferences_node_links_alter(array &$links, NodeInterface $node, array &$context) {
if ($context['view_mode'] != 'rss') {
$user = \Drupal::currentUser();
$is_admin = in_array('administrator', $user->getRoles());
$is_front = \Drupal::service('path.matcher')->isFrontPage();
if(!$is_admin){
$can_add_child_page = in_array('Add content and child pages to books and manage their hierarchies', user_role_permissions($user->getRoles()));
}
if ($context['view_mode'] == 'full' && node_is_page($node)) {
$nid = $node->id();
$link['toggleSidebar'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:#toggleSidebar'),
'attributes' => [
'title' => t('Toggle sidebar'),
'id' => 'sidebar_collapse',
'class' => 'd-none d-md-block',
'data-tippy-content' => t('Toggle sidebar'),
'data-toggle' => 'tooltip',
'aria-label' => 'Toggle sidebar',
]
];
if($is_admin){
$link['accessibilityPanel'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:#toggleA11y'),
'attributes' => [
'title' => t('Accessibility Tools'),
'data-tippy-content' => t('Accessibility Tools'),
'id' => 'toggle_a11y_tools',
'onclick' => 'jQuery("#accessibilityPanel").modal("toggle")',
'data-toggle' => 'tooltip',
'aria-label' => 'Accessibility tools',
]
];
$link['paragraphInspector'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:#toggleInspector'),
'attributes' => [
'title' => t('Identify Target'),
'data-tippy-content' => t('Identify Target'),
'id' => 'toggle_inspector',
'class' => 'toggle-inspector',
'data-toggle' => 'tooltip',
'aria-label' => 'Identify Target',
]
];
}
$link['keyboardShortcuts'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:#toggleShortcuts'),
'attributes' => [
'title' => t('Keyboard Shortcuts'),
'data-tippy-content' => t('Keyboard Shortcuts'),
'id' => 'toggle_help',
'onclick' => 'jQuery("#keyboardShortcuts").modal("toggle")',
'data-toggle' => 'tooltip',
'aria-label' => 'Keyboard shortcuts',
]
];
$link['userPreferences'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:#togglePreferences'),
'attributes' => [
'title' => t('Preferences'),
'id' => 'toggle_preferences',
'onclick' => 'jQuery("#userPreferences").modal("toggle")',
'data-tippy-content' => t('Preferences'),
'data-toggle' => 'tooltip',
'aria-label' => 'User preferences',
]
];
$link['fullScreen'] = [
'title' => t(' '
),
'url' => Url::fromUri('internal:#fullScreen'),
'attributes' => [
'title' => t('Enter Fullscreen'),
'id' => 'toggle_fullscreen',
'class' => 'toggle-fullscreen',
'data-tippy-content' => t('Enter Fullscreen'),
'data-toggle' => 'tooltip',
'aria-label' => 'Toggle fullscreen',
]
];
if($is_admin || $can_add_child_page){
$link['addPage'] = [
'title' => t('
'),
'url' => Url::fromUri('internal:/node/add/lesson?parent='.$nid),
'attributes' => [
'title' => t('Add child page'),
'id' => 'add_child_page',
'data-tippy-content' => t('Add child page'),
'data-toggle' => 'tooltip',
'aria-label' => 'Add child page',
]
];
/*
$link['createCitation'] = [
'title' => t(' '
),
'url' => Url::fromUri('internal:#createCitation'),
'attributes' => [
'title' => t('Create Citation (not functional)'),
'id' => 'create_citation',
'class' => 'create-citation',
'onclick' => 'createCitation()',
'data-tippy-content' => t('Create Citation (not functional)'),
'data-toggle' => 'tooltip',
'aria-label' => 'Copy Citation',
]
];
*/
}
if(!$is_front){
$link['printerFriendly'] = [
'title' => t(' '),
'url' => Url::fromUri('internal:/book/export/html/'.$nid),
'attributes' => [
'title' => t('Printer friendly version'),
'id' => 'printer_friendly',
'data-toggle' => 'tooltip',
'data-tippy-content' => t('Printer friendly version'),
'aria-label' => 'Printer friendly version',
]
];
}
}
if (!empty($link)) {
$links['user_preferences'] = [
'#theme' => 'links__user_preferences',
'#links' => $link,
'#attributes' => ['class' => ['links', 'inline']],
];
}
}
}