1

How can one add a field in views with a link to a custom Action plugin?

With bulk operations it's possible to create a checkbox to perform an action to a set of results. My actions have an access check that may be different per result so using the checkbox would result in a lot of warnings when the user tries to perform the action and doesn't have access.

I'd prefer to show the action as a link and only show the link when the user has access.

0

I'm thinking about setting up a route with a csrf token and an access check on a controller that manually performs the action:

my_module.my_action_callback:
  path: '/node/{node}/my_action_callback'
  defaults:
    _controller: '\Drupal\my_module\Controller\ActionController::my_action'
    _title: 'My action'
  requirements:
    _permission: 'perform my action'
    _csrf_token: 'TRUE'
    _custom_access: '\Drupal\my_module\Controller\ActionController::my_action_access'

In ActionController::my_action I could perform the action programmatically:

\Drupal\system\Entity\Action::load('foo')->execute($data);

I had hoped there was a less complex and more elegant way using an existing view plugin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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