I have a page view that table format. I have Content: Edit link field. I want to hide the row that contains that field empty. The following is a screen shot for Content: Edit link settings regarding NO RESULTS BEHAVIOR:

enter image description here

And I want to hide the rows like in the below screen shot with no edit link:

enter image description here

By the way, I hide some of edit links, due to using custom module has a hook implements hook_node_access to prevent some users from editing some other user's contents (depending on roles and content ownership)

2 Answers 2


You can use views_php

  1. Add Content: Nid as a Field in your view and exclude it from display (if you not added it before).

  2. Add a Global: PHP filter and include the following snippet:

    return !node_access('update', node_load($row->nid));

also another way is using hook_views_pre_render and check you results if user has not access to that row(result) unset it from output array.

update part

As @Aaron mention good note in commentI explain second solution with more details

 * Implementation of hook_views_pre_render().
function MODULENAME_views_pre_render(&$view) {
  if ($view->name == 'my_view' && $view->current_display == 'my_display') {
    // View result update logic.
    // e.g.
    // $result = array();
    // foreach ($view->result as $k => $row) {
    //   if (!node_access('update', node_load($view->result[$k]->nid))) {
    //     $result[] = $row;
    //   }
    // }

    // Assuming $result has data as per your logic.
    // Update the pager according to result.
    $view->query->pager->total_items = count($result);
    // Add results to view.
    $view->result = $result;
  • As I mentioned in my solution, this will work but will break pagination as well as things like "view more" links and empty results text. Consider a situation in which you have 5 items per page and your view returns 20 items. If the user can't edit any of the first 5 items then he will see an empty page with no results and merely a pager to view the next page. Maybe this is tolerable for you but you should be aware of the problem.
    – Aaron
    Aug 26, 2015 at 13:51
  • I'm actually not referring to that bug. Even with that patch, the problem is that you're deciding what to show/hide after the query has been run, which means that, though your query might request the first 5 or 10 or whatever items but your view has no idea of how many of those will actually be shown to the user so you will have an inconsistent number of items on each page, or even no items at all.
    – Aaron
    Aug 26, 2015 at 16:52
  • I downvoted because I do not think that a solution that results in buggy results is a good solution. I think the right solution is to implement hook_node_access_records to write the access info for the nodes to the database so that views can work properly.
    – Aaron
    Aug 26, 2015 at 16:53
  • For the record -- I'm not talking to myself but zhilevan deleted a few comments.
    – Aaron
    Aug 26, 2015 at 17:00
  • @Aaron I got what you mean, tnx for your note , I update my question
    – Yuseferi
    Aug 26, 2015 at 17:16

If you really are using hook_node_access to prevent users from editing those nodes then there's no good solution. You could implement some Views hooks to hide the results, but then things like pagination are going to be screwed up since pagination is done at query time and it's impossible to write a query that will honor the results of hook_node_access.

If, on the other hand, you're using hook_node_access_records to actually write the node permissions to the database then you can use this Views patch: https://www.drupal.org/node/620392#comment-10222425

The patch will allow you to add a Content Access filter to your view and filter to only show content the user's allowed to edit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.