By dpi on
Change record status:
Draft (View all draft change records)
Project:
Issue links:
Description:
Before
.permissions.yml
permission_callbacks:
- \Drupal\my_module\MyPermissions::myPermissionsPermissions class
declare(strict_types=1);
namespace Drupal\my_module;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
final class MyPermissions {
use StringTranslationTrait;
public function __construct(
private readonly \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager,
TranslationInterface $translation,
) {
$this->setStringTranslation($translation);
}
public function myPermissions(): array {
return [
'my_module permission' => [
'title' => $this->t('My Permission'),
],
];
}
}
After
User permission providers are now created as entries in a.services.yml file, with no changes to how provider classes are constructed:
services:
my_permission_provider:
class: Drupal\my_module\MyPermissions
autowire: true
tags:
- { name: 'user.permission_provider', method: 'myPermissions', provider: 'my_module' }
Drupal\my_module\MyPermissions: '@my_permission_provider'
Deprecations
Existing implementations of permission_callbacks have been removed from core, while associated permission classes have been updated.
- They remove
\Drupal\Core\DependencyInjection\ContainerInjectionInterface, instead relying on autowiring for dependency injection. - Parameters have been updated, such that they are renamed to camelcase, and use contructor promotion, with associated parameter documentation in constructor removed. Parameter position and typing has not changed.
- Most explicit property definitions have been removed, in favor of constructor promotion.
Impacts:
Module developers