Skip to content
Snippets Groups Projects

Fix not valid context for entity context when editing the default layout entity types or bundles

Closed Carlos Romero requested to merge issue/layout_builder_perms-3392780:2.1.x-3392780 into 2.1.x
2 files
+ 35
29
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 26
22
@@ -101,25 +101,32 @@ class AccessManager implements AccessManagerInterface {
// Create a list of filters to only load plugins we need.
[$component, $action] = explode('_', $operation);
$layout = $route_match ? $this->getLayoutFromRouteMatch($route_match, $section_storage) : NULL;
$entity = $section_storage->getContextValue('entity');
$filters = [
'operation' => $operation,
'component' => $component,
'action' => $layout ? ($layout->getThirdPartySetting('layout_builder_perms', 'action', '') ?: $action) : $action,
'layout' => $layout ? $layout->getLayoutId() : NULL,
'block_type' => $route_match ? $this->getBlockTypeFromRouteMatch($route_match) : NULL,
'entity_type' => $entity ? $entity->getEntityTypeId() : NULL,
'bundle' => $entity ? $entity->bundle() : NULL,
];
foreach ($this->layoutBuilderPermissions->getPermissionPlugins(array_filter($filters)) as $permission_plugin) {
// Set the plugin context if the plugin is context aware.
if ($permission_plugin instanceof ContextAwarePluginInterface) {
$this->setPluginContext($permission_plugin, $operation, $route_match, $section_storage);
}
try {
$entity = $section_storage->getContextValue('entity');
}
catch (ContextException $e) {
$entity = NULL;
}
if ($entity) {
$filters = [
'operation' => $operation,
'component' => $component,
'action' => $layout ? ($layout->getThirdPartySetting('layout_builder_perms', 'action', '') ?: $action) : $action,
'layout' => $layout ? $layout->getLayoutId() : NULL,
'block_type' => $route_match ? $this->getBlockTypeFromRouteMatch($route_match) : NULL,
'entity_type' => $entity ? $entity->getEntityTypeId() : NULL,
'bundle' => $entity ? $entity->bundle() : NULL,
];
foreach ($this->layoutBuilderPermissions->getPermissionPlugins(array_filter($filters)) as $permission_plugin) {
// Set the plugin context if the plugin is context aware.
if ($permission_plugin instanceof ContextAwarePluginInterface) {
$this->setPluginContext($permission_plugin, $operation, $route_match, $section_storage);
}
// Check access if the plugin applies.
if ($permission_plugin->applies()) {
$result = $result->andIf($permission_plugin->access($operation, $account));
// Check access if the plugin applies.
if ($permission_plugin->applies()) {
$result = $result->andIf($permission_plugin->access($operation, $account));
}
}
}
@@ -204,10 +211,7 @@ class AccessManager implements AccessManagerInterface {
// Allow other modules to add additional contexts.
if ($plugin instanceof LayoutBuilderPermissionInterface) {
$event = new LayoutBuilderPermissionPluginContexts($plugin, $operation, $route_match, $section_storage);
\Drupal::service('event_dispatcher')->dispatch(
LayoutBuilderPermissionPluginContexts::EVENT_NAME,
$event
);
\Drupal::service('event_dispatcher')->dispatch($event, LayoutBuilderPermissionPluginContexts::EVENT_NAME);
}
}
Loading