- Issue created by @codebymikey
- 🇫🇷France andypost
There's special
no_ui
option already, are you gonna make it dynamic? Hi Andrey, the idea is to have the actions hidden from the selection options only if the user doesn't have permission to use them in the first place. I believe
no_ui
would hide it for all users, and wouldn't want to change how that definition already works.My specific use case was related to the 🐛 Revision user incorrectly appears as anonymous user when node author is cancelled Needs work issue, and providing a way to stop the "Cancel the selected user accounts" action from being shown to the user unless they had the
cancel account
permission since it was confusing to have an action which they couldn't actually use.The addition of this requirements definition will help clean up the UI a bit more.
My version of this was implemented via an alter hook:
/** * Implements hook_action_info_alter(). */ function mycustommodule_action_info_alter(array &$definitions) { $cancel_user_actions = [ 'user_cancel_user_action', 'vbo_cancel_user_action', ]; foreach ($cancel_user_actions as $cancel_user_action) { if (isset($definitions[$cancel_user_action])) { /* @see \Drupal\views_bulk_operations\Plugin\views\field\ViewsBulkOperationsBulkForm::getBulkOptions() */ // Added as part of https://www.drupal.org/project/drupal/issues/3468097 $definitions[$cancel_user_action]['requirements']['_permission'] = 'cancel account'; } } }
P.S. We also don't have an
hook_action_info_alter()
API function for reference.