diff -u b/core/modules/book/book.module b/core/modules/book/book.module --- b/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -126,8 +126,8 @@ if (isset($node->book['depth'])) { if ($view_mode == 'full' && node_is_page($node)) { $child_type = config('book.settings')->get('child_type'); - $account = Drupal::request()->attributes->get('_account'); - if (($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { + $user = Drupal::request()->attributes->get('_account'); + if (($user->hasPermission('add content to books') || $user->hasPermission('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { $links['book_add_child'] = array( 'title' => t('Add child page'), 'href' => 'node/add/' . $child_type, @@ -135,7 +135,7 @@ ); } - if ($account->hasPermission('access printer-friendly version')) { + if ($user->hasPermission('access printer-friendly version')) { $links['book_printer'] = array( 'title' => t('Printer-friendly version'), 'href' => 'book/export/html/' . $node->id(), @@ -225,7 +225,9 @@ * The node whose export page is to be viewed. */ function book_export_access(EntityInterface $node) { - return Drupal::request()->attributes->get('_account')->hasPermission('access printer-friendly version') && node_access('view', $node); + $user = Drupal::request()->attributes->get('_account'); + $user = (empty($user)) ? drupal_anonymous_user() : $user; + return $user->hasPermission('access printer-friendly version') && node_access('view', $node); } /** @@ -306,11 +308,11 @@ */ function book_form_node_form_alter(&$form, &$form_state, $form_id) { $node = $form_state['controller']->getEntity(); - $account = Drupal::request()->attributes->get('_account'); - $access = $account->hasPermission('administer book outlines'); + // Get current user object. + $user = Drupal::request()->attributes->get('_account'); + $access = $user->hasPermission('administer book outlines'); if (!$access) { - - if ($account->hasPermission('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->type))) { + if ($user->hasPermission('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->type))) { // Already in the book hierarchy, or this node type is allowed. $access = TRUE; } @@ -882,9 +884,10 @@ * Implements hook_node_prepare_form(). */ function book_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) { + // Get current user object. + $user = Drupal::request()->attributes->get('_account'); // Prepare defaults for the add/edit form. - $account = Drupal::request()->attributes->get('_account'); - if (empty($node->book) && ($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines'))) { + if (empty($node->book) && ($user->hasPermission('add content to books') || $user->hasPermission('administer book outlines'))) { $node->book = array(); $query = \Drupal::request()->query;