diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index 611537b..7f2f83d 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -209,7 +209,7 @@ function theme_book_admin_table($variables) { $rows = array(); $destination = drupal_get_destination(); - $access = user_access('administer nodes'); + $access = Drupal::request()->attributes->get('_account')->hasPermission('administer nodes'); foreach (element_children($form) as $key) { $nid = $form[$key]['nid']['#value']; $href = $form[$key]['href']['#value']; diff --git a/core/modules/book/book.module b/core/modules/book/book.module index e113661..c21020a 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -126,7 +126,8 @@ function book_node_view_link(EntityInterface $node, $view_mode) { if (isset($node->book['depth'])) { if ($view_mode == 'full' && node_is_page($node)) { $child_type = config('book.settings')->get('child_type'); - if ((user_access('add content to books') || user_access('administer book outlines')) && node_access('create', $child_type) && $node->status == 1 && $node->book['depth'] < MENU_MAX_DEPTH) { + $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) { $links['book_add_child'] = array( 'title' => t('Add child page'), 'href' => 'node/add/' . $child_type, @@ -134,7 +135,7 @@ function book_node_view_link(EntityInterface $node, $view_mode) { ); } - if (user_access('access printer-friendly version')) { + if ($account->hasPermission('access printer-friendly version')) { $links['book_printer'] = array( 'title' => t('Printer-friendly version'), 'href' => 'book/export/html/' . $node->id(), @@ -224,7 +225,7 @@ function book_menu() { * The node whose export page is to be viewed. */ function book_export_access(EntityInterface $node) { - return user_access('access printer-friendly version') && node_access('view', $node); + return Drupal::request()->attributes->get('_account')->hasPermission('access printer-friendly version') && node_access('view', $node); } /** @@ -240,7 +241,7 @@ function book_export_access(EntityInterface $node) { * @see book_menu() */ function _book_outline_access(EntityInterface $node) { - return user_access('administer book outlines') && node_access('view', $node); + return Drupal::request()->attributes->get('_account')->hasPermission('administer book outlines') && node_access('view', $node); } /** @@ -305,9 +306,11 @@ function book_get_books() { */ function book_form_node_form_alter(&$form, &$form_state, $form_id) { $node = $form_state['controller']->getEntity(); - $access = user_access('administer book outlines'); + $account = Drupal::request()->attributes->get('_account'); + $access = $account->hasPermission('administer book outlines'); if (!$access) { - if (user_access('add content to books') && ((!empty($node->book['mlid']) && !$node->isNew()) || book_type_is_allowed($node->type))) { + + if ($account->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; } @@ -459,7 +462,7 @@ function _book_add_form_elements(&$form, &$form_state, EntityInterface $node) { } } - if (user_access('create new books') && ($nid == 'new' || ($nid != $node->book['original_bid']))) { + if (Drupal::request()->attributes->get('_account')->hasPermission('create new books') && ($nid == 'new' || ($nid != $node->book['original_bid']))) { // The node can become a new book, if it is not one already. $options = array($nid => t('- Create a new book -')) + $options; } @@ -812,7 +815,7 @@ function book_page_alter(&$page) { */ function book_node_presave(EntityInterface $node) { // Always save a revision for non-administrators. - if (!empty($node->book['bid']) && !user_access('administer nodes')) { + if (!empty($node->book['bid']) && !Drupal::request()->attributes->get('_account')->hasPermission('administer nodes')) { $node->setNewRevision(); } // Make sure a new node gets a new menu link. @@ -880,7 +883,8 @@ function book_node_predelete(EntityInterface $node) { */ function book_node_prepare_form(NodeInterface $node, $form_display, $operation, array &$form_state) { // Prepare defaults for the add/edit form. - if (empty($node->book) && (user_access('add content to books') || user_access('administer book outlines'))) { + $account = Drupal::request()->attributes->get('_account'); + if (empty($node->book) && ($account->hasPermission('add content to books') || $account->hasPermission('administer book outlines'))) { $node->book = array(); $query = \Drupal::request()->query; diff --git a/core/modules/book/book.pages.inc b/core/modules/book/book.pages.inc index 4cd7e25..0388ed2 100644 --- a/core/modules/book/book.pages.inc +++ b/core/modules/book/book.pages.inc @@ -68,7 +68,7 @@ function book_export($type, EntityInterface $node) { * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ function book_export_html(EntityInterface $node) { - if (user_access('access printer-friendly version')) { + if (Drupal::request()->attributes->get('_account')->hasPermission('access printer-friendly version')) { if (isset($node->book)) { $tree = book_menu_subtree_data($node->book); $contents = book_export_traverse($tree, 'book_node_export');