Loading core/modules/user/src/Plugin/views/filter/Roles.php +5 −1 Changes for core/modules/user/src/Plugin/views/filter/Roles.php: 5 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -88,9 +88,13 @@ public function calculateDependencies() { } foreach ((array) $this->value as $role_id) { $role = $this->roleStorage->load($role_id); if ($role = $this->roleStorage->load($role_id)) { $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); } } return $dependencies; } Loading core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php +25 −0 Changes for core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php: 25 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\user\Entity\Role; use Drupal\views\Entity\View; use Drupal\views\Views; use PHPUnit\Framework\Error\Warning; /** * Tests the roles filter handler. Loading Loading @@ -95,4 +96,28 @@ public function testDependencies() { $this->assertEqual($expected, $view->getDependencies()); } /** * Tests that a warning is triggered if the filter references a missing role. */ public function testMissingRole() { $role = Role::create(['id' => 'test_user_role']); $role->save(); /** @var \Drupal\views\Entity\View $view */ $view = View::load('test_user_name'); $display = &$view->getDisplay('default'); $display['display_options']['filters']['roles_target_id'] = [ 'id' => 'roles_target_id', 'table' => 'user__roles', 'field' => 'roles_target_id', 'value' => ['test_user_role' => 'test_user_role'], 'plugin_id' => 'user_roles', ]; // Ensure no warning is triggered before the role is deleted. $view->calculateDependencies(); $role->delete(); $this->expectException(Warning::class); $this->expectExceptionMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.'); $view->calculateDependencies(); } } Loading
core/modules/user/src/Plugin/views/filter/Roles.php +5 −1 Changes for core/modules/user/src/Plugin/views/filter/Roles.php: 5 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -88,9 +88,13 @@ public function calculateDependencies() { } foreach ((array) $this->value as $role_id) { $role = $this->roleStorage->load($role_id); if ($role = $this->roleStorage->load($role_id)) { $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); } } return $dependencies; } Loading
core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php +25 −0 Changes for core/modules/user/tests/src/Kernel/Views/HandlerFilterRolesTest.php: 25 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,6 +5,7 @@ use Drupal\user\Entity\Role; use Drupal\views\Entity\View; use Drupal\views\Views; use PHPUnit\Framework\Error\Warning; /** * Tests the roles filter handler. Loading Loading @@ -95,4 +96,28 @@ public function testDependencies() { $this->assertEqual($expected, $view->getDependencies()); } /** * Tests that a warning is triggered if the filter references a missing role. */ public function testMissingRole() { $role = Role::create(['id' => 'test_user_role']); $role->save(); /** @var \Drupal\views\Entity\View $view */ $view = View::load('test_user_name'); $display = &$view->getDisplay('default'); $display['display_options']['filters']['roles_target_id'] = [ 'id' => 'roles_target_id', 'table' => 'user__roles', 'field' => 'roles_target_id', 'value' => ['test_user_role' => 'test_user_role'], 'plugin_id' => 'user_roles', ]; // Ensure no warning is triggered before the role is deleted. $view->calculateDependencies(); $role->delete(); $this->expectException(Warning::class); $this->expectExceptionMessage('The test_user_role role does not exist. You should review and fix the configuration of the test_user_name view.'); $view->calculateDependencies(); } }