Commit 4361e679 authored by catch's avatar catch

Issue #2120117 by Wim Leers, nod_: Fixed drupalSettings.user.uid added to page...

Issue #2120117 by Wim Leers, nod_: Fixed drupalSettings.user.uid added to page even if there is no other JS; drupal.node-new-comments-link lib added for anon users.
parent 75debc11
......@@ -595,7 +595,7 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v
'#links' => $links,
'#attributes' => array('class' => array('links', 'inline')),
);
if ($view_mode == 'teaser' && \Drupal::moduleHandler()->moduleExists('history')) {
if ($view_mode == 'teaser' && \Drupal::moduleHandler()->moduleExists('history') && \Drupal::currentUser()->isAuthenticated()) {
$entity->content['links']['#attached']['library'][] = array('comment', 'drupal.node-new-comments-link');
}
}
......
......@@ -116,16 +116,25 @@ function user_theme() {
function user_page_build(&$page) {
$path = drupal_get_path('module', 'user');
$page['#attached']['css'][$path . '/css/user.module.css'] = array('every_page' => TRUE);
}
/**
* Implements hook_js_alter().
*/
function user_js_alter(&$javascript) {
// If >=1 JavaScript asset has declared a dependency on drupalSettings, the
// 'settings' key will exist. Thus when that key does not exist, return early.
if (!isset($javascript['settings'])) {
return;
}
// Provide the user ID in drupalSettings to allow JavaScript code to customize
// the experience for the end user, rather than the server side, which would
// break the render cache.
global $user;
$page['#attached']['js'][] = array(
'type' => 'setting',
'data' => array('user' => array(
'uid' => $user->id(),
)),
$javascript['settings']['data'][] = array(
'user' => array(
'uid' => \Drupal::currentUser()->id(),
),
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment