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.
Comments
Comment #2
gordon commentedHere is the patch.
Comment #3
joshua.roberson commentedWhen I have time, I will try to test everything.
Comment #4
joshua.roberson commentedComment #5
recrit commentedWorks.
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.
Comment #6
recrit commentedComment #8
joshua.roberson commentedComment #9
joshua.roberson commented