You are here

function book_access_node_view_alter in Book access 1.x

Same name and namespace in other branches
  1. 7.2 book_access.module \book_access_node_view_alter()

Implements hook_node_view_alter().

Enables the link "Add child page" only for users who have the right permission.

File

./book_access.module, line 293

Code

function book_access_node_view_alter(&$build) {
  if (!empty($node->book['bid']) && !empty($build['links']['book']['#links'])) {
    $links = $build['links']['book']['#links'];
    $node = $build['#node'];
    if (\Drupal::currentUser()
      ->hasPermission('administer nodes')) {
      return;
    }
    if (!empty($links['book_add_child'])) {

      // @FIXME
      // // @FIXME
      // // This looks like another module's variable. You'll need to rewrite this call
      // // to ensure that it uses the correct configuration object.
      // $bool = (
      //         (
      //           (
      //             \Drupal::currentUser()->hasPermission('add content to books') &&
      //             BookAccess::checkGrant($node->book['bid'], 'add_child')
      //           ) ||
      //           \Drupal::currentUser()->hasPermission('administer book outlines')
      //         ) &&
      //         node_access('create', variable_get('book_child_type', 'book')) &&
      //         ($node->status == 1) &&
      //         ($node->book['depth'] < MENU_MAX_DEPTH)
      //       );
      //      if (!$bool) {
      //        unset($links['book_add_child']);
      //      }
    }
  }
}