Initial Drupal 11 with DDEV setup
This commit is contained in:
59
vendor/chi-teck/drupal-code-generator/templates/Service/_access-checker/access-checker.twig
vendored
Normal file
59
vendor/chi-teck/drupal-code-generator/templates/Service/_access-checker/access-checker.twig
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
{% import '@lib/di.twig' as di %}
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\{{ machine_name }}\Access;
|
||||
|
||||
{% apply sort_namespaces %}
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Routing\Access\AccessInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
{% if services %}
|
||||
{{ di.use(services) }}
|
||||
{% endif %}
|
||||
{% endapply %}
|
||||
|
||||
/**
|
||||
* Checks if passed parameter matches the route configuration.
|
||||
*
|
||||
* Usage example:
|
||||
* @code
|
||||
* foo.example:
|
||||
* path: '/example/{parameter}'
|
||||
* defaults:
|
||||
* _title: 'Example'
|
||||
* _controller: '\Drupal\{{ machine_name }}\Controller\{{ machine_name|camelize }}Controller'
|
||||
* requirements:
|
||||
* {{ requirement }}: 'some value'
|
||||
* @endcode
|
||||
*/
|
||||
final class {{ class }} implements AccessInterface {
|
||||
{% if services %}
|
||||
|
||||
/**
|
||||
* Constructs {{ class|article }} object.
|
||||
*/
|
||||
public function __construct(
|
||||
{{ di.signature(services) }}
|
||||
) {}
|
||||
{% endif %}
|
||||
|
||||
/**
|
||||
* Access callback.
|
||||
*
|
||||
* @DCG
|
||||
* Drupal does some magic when resolving arguments for this callback. Make
|
||||
* sure the parameter name matches the name of the placeholder defined in the
|
||||
* route, and it is of the same type.
|
||||
* The following additional parameters are resolved automatically.
|
||||
* - \Drupal\Core\Routing\RouteMatchInterface
|
||||
* - \Drupal\Core\Session\AccountInterface
|
||||
* - \Symfony\Component\HttpFoundation\Request
|
||||
* - \Symfony\Component\Routing\Route
|
||||
*/
|
||||
public function access(Route $route, mixed $parameter): AccessResult {
|
||||
return AccessResult::allowedIf($parameter === $route->getRequirement('{{ requirement }}'));
|
||||
}
|
||||
|
||||
}
|
||||
9
vendor/chi-teck/drupal-code-generator/templates/Service/_access-checker/services.twig
vendored
Normal file
9
vendor/chi-teck/drupal-code-generator/templates/Service/_access-checker/services.twig
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{% import '@lib/di.twig' as di %}
|
||||
services:
|
||||
access_check.{{ machine_name }}.{{ requirement|trim('_') }}:
|
||||
class: Drupal\{{ machine_name }}\Access\{{ class }}
|
||||
{% if services %}
|
||||
arguments: [{{ di.arguments(services) }}]
|
||||
{% endif %}
|
||||
tags:
|
||||
- { name: access_check, applies_to: {{ requirement }} }
|
||||
Reference in New Issue
Block a user