Sometimes I need to give two roles access to the same view, but one should get bulk operations and the other should not. It would be most helpful to be able to set a condition on which to add bulk operations (e.g. role, permission, etc.), and if the condition isn't met, fall back to a standard table style.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bojanz’s picture

WorldFallz’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

I'm trying to figure out if it's possible to conditionally hide the VBO column for certain roles. From what I've found going through the issue queue (the link above is for d6 and dead ended in a won't fix), a user without permission for any actions should not see it if the 'hide empty column' option is selected in the view table display settings.

I'm testing this now, and for the anonymous role which only has the 'view published content', 'view comments', and 'use search' permissions, they still see the column.

Is this still the recommended method and I'm seeing a bug? Or is this simply not possible and i'll have to create separate displays for separate roles?

I can work on a patch to add it to the vbo column settings if it would be considered. But it seems the 'hide empty column' option makes more sense.

bojanz’s picture

Status: Active » Postponed (maintainer needs more info)

Yes, the VBO column will be hidden if no actions are available (due to insufficient access, for example).
No setting needs to be changed (not even "hide empty column").

You say that the column still shows up, are there any actions in the dropdown? If no, then it's a bug. If yes, then your access is not configured properly.

WorldFallz’s picture

I just verified I can reproduce on simplytest.me with views 7.x-3.8 and vbo 7.x-3.2.

Steps to reproduce:

  1. fire up a site with vbo on simplytest.me (it will also include all module dependencies).
  2. enable views_ui and vbo (dependencies with also be enabled).
  3. create a test article or 2 with lorem ipsum.
  4. navigate to admin/people/permissions and remove all permissions from the 'anonymous' role except "View published content".
  5. create a basic content page view - keep all the defaults, change to a 'fields' view, check the 'Hide empty fields' option in the fields settings, add the vbo: content field and at least the 'delete item' action. An export of the view I used is attached.
  6. Navigate to the view while logged in and see the VBO drop down and checboxes with the actions checked showing up in the drop down.
  7. hit the 'logout' link, navigate to the view again, and see the checkboxes with an empty drop down as anonymous:
Anonymous Authenticated (admin)
bojanz’s picture

Status: Postponed (maintainer needs more info) » Active
SpadXIII’s picture

a little note for people coming here looking for how to conditionally disable VBO and not finding a way to do it. I figured a (dirty? hacky?) way to do it like this:


/**
 * Implements hook_views_bulk_operations_form_alter().
 */
function MYMODULE_views_bulk_operations_form_alter(&$form, &$form_state, $vbo) {
  $view = $form_state['build_info']['args'][0];
  $some_other_condition = TRUE; // @todo replace with a proper condition.
  if ($view->name == 'admin_nodes' && $some_other_condition) {
    // Remove the VBO form substitutions so views doesn't find any when it needs to render the form.
    $vbo_subs = views_bulk_operations_views_form_substitutions();
    $hide_subs = array_fill_keys(array_keys($vbo_subs), '');
    $form['output']['#markup'] = str_replace(array_keys($hide_subs), array_values($hide_subs), $form['output']['#markup']);

    // Hide all VBO fields/items.
    $form['views_bulk_operations']['#access'] =
      $form['select_all']['#access'] =
      $form['select']['#access'] =
      $form['select_all_markup']['#access'] = FALSE;
  }
}
smulvih2’s picture

Approach in #6 works for me!