diff --git a/panels_ipe/panels_ipe.services.yml b/panels_ipe/panels_ipe.services.yml new file mode 100644 index 0000000..a10a616 --- /dev/null +++ b/panels_ipe/panels_ipe.services.yml @@ -0,0 +1,4 @@ +services: + plugin.manager.ipe_access: + class: Drupal\panels_ipe\Plugin\IPEAccessManager + parent: default_plugin_manager diff --git a/panels_ipe/src/Annotation/IPEAccess.php b/panels_ipe/src/Annotation/IPEAccess.php new file mode 100644 index 0000000..0239d8e --- /dev/null +++ b/panels_ipe/src/Annotation/IPEAccess.php @@ -0,0 +1,38 @@ +account->hasPermission('access panels in-place editing') && $this->panelsStorage->access($panels_display->getStorageType(), $panels_display->getStorageId(), 'update', $this->account)->isAllowed(); + if ($has_permission) { + $has_permission = \Drupal::service('plugin.manager.ipe_access')->access($panels_display); + } // Attach the Panels In-place editor library based on permissions. if ($has_permission) { diff --git a/panels_ipe/src/Plugin/IPEAccessBase.php b/panels_ipe/src/Plugin/IPEAccessBase.php new file mode 100644 index 0000000..609e2a0 --- /dev/null +++ b/panels_ipe/src/Plugin/IPEAccessBase.php @@ -0,0 +1,12 @@ +alterInfo('panels_ipe_ipe_access_info'); + $this->setCacheBackend($cache_backend, 'panels_ipe_ipe_access_plugins'); + } + + /** + * {@inheritdoc} + */ + public function applies(PanelsDisplayVariant $display) { + $applies = []; + foreach ($this->getDefinitions() as $plugin_id => $definition) { + /** @var \Drupal\panels_ipe\Plugin\IPEAccessInterface $plugin */ + $plugin = $this->createInstance($plugin_id); + if ($plugin->applies($display)) { + $applies[$plugin_id] = $plugin; + } + } + return $applies; + } + + /** + * {@inheritdoc} + */ + public function access(PanelsDisplayVariant $display) { + foreach ($this->applies($display) as $plugin_id => $plugin) { + if (!$plugin->access($display)) { + return FALSE; + } + } + return TRUE; + } + +} diff --git a/panels_ipe/src/Plugin/IPEAccessManagerInterface.php b/panels_ipe/src/Plugin/IPEAccessManagerInterface.php new file mode 100644 index 0000000..0024c25 --- /dev/null +++ b/panels_ipe/src/Plugin/IPEAccessManagerInterface.php @@ -0,0 +1,27 @@ +