-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update BNF server content view permissions.
This view should only be available if the `bnf_server` module is enabled.
- Loading branch information
Showing
5 changed files
with
86 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
--- | ||
services: | ||
dpl_admin.version_helper: | ||
class: Drupal\dpl_admin\Services\VersionHelper | ||
dpl_admin.bnf_server_access: | ||
class: Drupal\dpl_admin\Plugin\views\access\BnfServerEnabledAccess | ||
arguments: | ||
$configuration: [] | ||
$plugin_id: 'dpl_admin.bnf_server_access' | ||
$plugin_definition: [] | ||
$module_handler: '@module_handler' |
73 changes: 73 additions & 0 deletions
73
web/modules/custom/dpl_admin/src/Plugin/views/access/BnfServerEnabledAccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Drupal\dpl_admin\Plugin\views\access; | ||
|
||
use Drupal\Core\Access\AccessResult; | ||
use Drupal\Core\Extension\ModuleHandlerInterface; | ||
use Drupal\Core\Session\AccountInterface; | ||
use Drupal\views\Plugin\views\access\AccessPluginBase; | ||
use Psr\Container\ContainerInterface; | ||
use Symfony\Component\Routing\Route; | ||
|
||
/** | ||
* A custom access handler, that returns Allowed if bnf_server is enabled. | ||
* | ||
* This is necessary as we have views and content that should only be available | ||
* on the BNF server. | ||
* | ||
* @ingroup views_access_plugins | ||
* | ||
* @ViewsAccess( | ||
* id = "bnf_server_access", | ||
* title = @Translation("Allowed if bnf_server is enabled.") | ||
* ) | ||
*/ | ||
class BnfServerEnabledAccess extends AccessPluginBase { | ||
|
||
/** | ||
* The module handler. | ||
*/ | ||
protected ModuleHandlerInterface $moduleHandler; | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __construct(array $configuration, $plugin_id, $plugin_definition, ModuleHandlerInterface $module_handler) { | ||
parent::__construct($configuration, $plugin_id, $plugin_definition); | ||
$this->moduleHandler = $module_handler; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): static { | ||
return new static( | ||
$configuration, | ||
$plugin_id, | ||
$plugin_definition, | ||
$container->get('module_handler'), | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function access(AccountInterface $account): bool { | ||
return $this->moduleHandler->moduleExists('bnf_server'); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function accessRoute(AccountInterface $account): AccessResult { | ||
return AccessResult::allowedIf($this->access($account)); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function alterRouteDefinition(Route $route): void { | ||
$route->setRequirement('_custom_access', 'dpl_admin.bnf_server_access:accessRoute'); | ||
} | ||
|
||
} |