I have added an action link to a view which will allow you to add a block directly from the view.

I used this example to do this.

example.add_example:
  route_name: 'block_content.add_form'
  route_parameters:
    block_content_type: 'example'
  title: 'Add example'
  class: \Drupal\menu_ui\Plugin\Menu\LocalAction\MenuLinkAdd
  appears_on:
    - view.example.page_1

The problem was that when it checks the access, Block Content Permissions was using the route view.example.page_1 instead of block_content.add_form

I have made a change to AccessControllerHandler::blockContentAddFormAccess() to include the correct route.

This seems to have fixed the problem, but I have not done a lot of testing.

CommentFileSizeAuthor
#2 action_links_broken-2966241-1.patch1.18 KBgordon

Comments

gordon created an issue. See original summary.

gordon’s picture

StatusFileSize
new1.18 KB

Here is the patch.

joshua.roberson’s picture

When I have time, I will try to test everything.

joshua.roberson’s picture

Status: Active » Needs review
recrit’s picture

Works.
Using a route match in the function argument is the correct method. An access function should never depend on the current route.
Access checkers such as Drupal\Core\Access\CustomAccessCheck::access() pass in arguments based on what route that they want check, The follow are possible arguments: Symfony\Component\Routing\Route, Drupal\Core\Routing\RouteMatch, Drupal\Core\Session\AccountProxy. The arguments are sniffed to match the argument passed in.

recrit’s picture

Status: Needs review » Reviewed & tested by the community

  • joshua.roberson committed e83d8f2 on 8.x-1.x authored by gordon
    Issue #2966241 by gordon: Access issue when adding action link to random...
joshua.roberson’s picture

Status: Reviewed & tested by the community » Fixed
joshua.roberson’s picture

Status: Fixed » Closed (fixed)