Loading core/.phpstan-baseline.php +0 −12 Original line number Diff line number Diff line Loading @@ -1898,18 +1898,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Functional/UserRegistrationRestTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#', 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Call to deprecated method expectWarningMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#', 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Variable \\$result in isset\\(\\) always exists and is not nullable\\.$#', 'count' => 1, Loading core/modules/user/src/Plugin/views/filter/Roles.php +21 −12 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\user\RoleStorageInterface; use Drupal\views\Attribute\ViewsFilter; use Drupal\views\Plugin\views\filter\ManyToOne; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading @@ -16,13 +17,6 @@ #[ViewsFilter("user_roles")] class Roles extends ManyToOne { /** * The role storage. * * @var \Drupal\user\RoleStorageInterface */ protected $roleStorage; /** * Constructs a Roles object. * Loading @@ -32,12 +26,23 @@ class Roles extends ManyToOne { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\user\RoleStorageInterface $role_storage * @param \Drupal\user\RoleStorageInterface $roleStorage * The role storage. * @param \Psr\Log\LoggerInterface|null $logger * The logger service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RoleStorageInterface $role_storage) { public function __construct( array $configuration, $plugin_id, $plugin_definition, protected readonly RoleStorageInterface $roleStorage, protected ?LoggerInterface $logger, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->roleStorage = $role_storage; if (!$logger) { @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3427368', E_USER_DEPRECATED); $this->logger = \Drupal::service('logger.channel.default'); } } /** Loading @@ -48,7 +53,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')->getStorage('user_role') $container->get('entity_type.manager')->getStorage('user_role'), $container->get('logger.channel.default'), ); } Loading Loading @@ -101,7 +107,10 @@ public function calculateDependencies() { $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName(); } else { trigger_error("The {$role_id} role does not exist. You should review and fix the configuration of the {$this->view->id()} view.", E_USER_WARNING); $this->logger->warning("View %view depends on role %role, but the role does not exist.", [ '%view' => $this->view->id(), '%role' => $role_id, ]); } } return $dependencies; Loading core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php +18 −2 Original line number Diff line number Diff line Loading @@ -4,9 +4,12 @@ namespace Drupal\Tests\user\Kernel\Views; use Drupal\Core\Logger\RfcLogLevel; use Drupal\user\Entity\Role; use Drupal\views\Entity\View; use Drupal\views\Views; use Prophecy\Argument; use Psr\Log\LoggerInterface; /** * Tests the roles filter handler. Loading Loading @@ -101,6 +104,11 @@ public function testDependencies() { * Tests that a warning is triggered if the filter references a missing role. */ public function testMissingRole() { $logger = $this->prophesize(LoggerInterface::class); $this->container->get('logger.factory') ->get('system') ->addLogger($logger->reveal()); $role = Role::create(['id' => 'test_user_role', 'label' => 'Test user role']); $role->save(); /** @var \Drupal\views\Entity\View $view */ Loading @@ -116,8 +124,16 @@ public function testMissingRole() { // Ensure no warning is triggered before the role is deleted. $view->calculateDependencies(); $role->delete(); $this->expectWarning(); $this->expectWarningMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.'); // Recalculate after role deletion. $logger->log( RfcLogLevel::WARNING, 'View %view depends on role %role, but the role does not exist.', Argument::allOf( Argument::withEntry('%view', 'test_user_name'), Argument::withEntry('%role', 'test_user_role'), ) )->shouldBeCalled(); $view->calculateDependencies(); } Loading Loading
core/.phpstan-baseline.php +0 −12 Original line number Diff line number Diff line Loading @@ -1898,18 +1898,6 @@ 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Functional/UserRegistrationRestTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#', 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Call to deprecated method expectWarningMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\: https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#', 'count' => 1, 'path' => __DIR__ . '/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php', ]; $ignoreErrors[] = [ 'message' => '#^Variable \\$result in isset\\(\\) always exists and is not nullable\\.$#', 'count' => 1, Loading
core/modules/user/src/Plugin/views/filter/Roles.php +21 −12 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ use Drupal\user\RoleStorageInterface; use Drupal\views\Attribute\ViewsFilter; use Drupal\views\Plugin\views\filter\ManyToOne; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** Loading @@ -16,13 +17,6 @@ #[ViewsFilter("user_roles")] class Roles extends ManyToOne { /** * The role storage. * * @var \Drupal\user\RoleStorageInterface */ protected $roleStorage; /** * Constructs a Roles object. * Loading @@ -32,12 +26,23 @@ class Roles extends ManyToOne { * The plugin_id for the plugin instance. * @param mixed $plugin_definition * The plugin implementation definition. * @param \Drupal\user\RoleStorageInterface $role_storage * @param \Drupal\user\RoleStorageInterface $roleStorage * The role storage. * @param \Psr\Log\LoggerInterface|null $logger * The logger service. */ public function __construct(array $configuration, $plugin_id, $plugin_definition, RoleStorageInterface $role_storage) { public function __construct( array $configuration, $plugin_id, $plugin_definition, protected readonly RoleStorageInterface $roleStorage, protected ?LoggerInterface $logger, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->roleStorage = $role_storage; if (!$logger) { @trigger_error('Calling ' . __METHOD__ . '() without the $logger argument is deprecated in drupal:10.3.0 and it will be required in drupal:11.0.0. See https://www.drupal.org/node/3427368', E_USER_DEPRECATED); $this->logger = \Drupal::service('logger.channel.default'); } } /** Loading @@ -48,7 +53,8 @@ public static function create(ContainerInterface $container, array $configuratio $configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager')->getStorage('user_role') $container->get('entity_type.manager')->getStorage('user_role'), $container->get('logger.channel.default'), ); } Loading Loading @@ -101,7 +107,10 @@ public function calculateDependencies() { $dependencies[$role->getConfigDependencyKey()][] = $role->getConfigDependencyName(); } else { trigger_error("The {$role_id} role does not exist. You should review and fix the configuration of the {$this->view->id()} view.", E_USER_WARNING); $this->logger->warning("View %view depends on role %role, but the role does not exist.", [ '%view' => $this->view->id(), '%role' => $role_id, ]); } } return $dependencies; Loading
core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php +18 −2 Original line number Diff line number Diff line Loading @@ -4,9 +4,12 @@ namespace Drupal\Tests\user\Kernel\Views; use Drupal\Core\Logger\RfcLogLevel; use Drupal\user\Entity\Role; use Drupal\views\Entity\View; use Drupal\views\Views; use Prophecy\Argument; use Psr\Log\LoggerInterface; /** * Tests the roles filter handler. Loading Loading @@ -101,6 +104,11 @@ public function testDependencies() { * Tests that a warning is triggered if the filter references a missing role. */ public function testMissingRole() { $logger = $this->prophesize(LoggerInterface::class); $this->container->get('logger.factory') ->get('system') ->addLogger($logger->reveal()); $role = Role::create(['id' => 'test_user_role', 'label' => 'Test user role']); $role->save(); /** @var \Drupal\views\Entity\View $view */ Loading @@ -116,8 +124,16 @@ public function testMissingRole() { // Ensure no warning is triggered before the role is deleted. $view->calculateDependencies(); $role->delete(); $this->expectWarning(); $this->expectWarningMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.'); // Recalculate after role deletion. $logger->log( RfcLogLevel::WARNING, 'View %view depends on role %role, but the role does not exist.', Argument::allOf( Argument::withEntry('%view', 'test_user_name'), Argument::withEntry('%role', 'test_user_role'), ) )->shouldBeCalled(); $view->calculateDependencies(); } Loading