Loading core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php +0 −10 Original line number Diff line number Diff line Loading @@ -59,16 +59,6 @@ public function testDraggableList(): void { $this->drupalGet('admin/people/roles'); $this->assertSession()->responseContains('<td>' . Html::escape($role_name)); // Make sure that NULL weights do not break the list builder. Use the // configuration API so that the value does not get type-casted according to // the configuration schema. \Drupal::configFactory() ->getEditable('user.role.role_0') ->set('weight', NULL) ->save(TRUE); $this->drupalGet('admin/people/roles'); $this->assertSession()->statusCodeEquals(200); } } core/modules/jsonapi/tests/src/Functional/RoleTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ protected function getExpectedDocument() { 'status' => TRUE, 'dependencies' => [], 'label' => 'Llama', 'is_admin' => NULL, 'is_admin' => FALSE, 'permissions' => [], 'drupal_internal__id' => 'llama', ], Loading core/modules/node/tests/src/Kernel/NodeAccessTestBase.php +1 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,7 @@ protected function setUp(): void { $this->installSchema('node', 'node_access'); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig('filter'); $this->installConfig('node'); $this->installConfig(['filter', 'node', 'user']); $this->accessHandler = \Drupal::entityTypeManager()->getAccessControlHandler('node'); Loading core/modules/user/config/schema/user.schema.yml +5 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,8 @@ user.flood: user.role.*: type: config_entity label: 'User role settings' constraints: FullyValidatable: ~ mapping: id: type: machine_name Loading @@ -143,6 +145,9 @@ user.role.*: sequence: type: string label: 'Permission' constraints: Callback: callback: [\Drupal\user\Entity\Role, getAllValidPermissions] action.configuration.user_add_role_action: type: mapping Loading core/modules/user/src/Entity/Role.php +20 −6 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ class Role extends ConfigEntityBase implements RoleInterface { * * @var bool */ protected $is_admin; protected $is_admin = FALSE; /** * {@inheritdoc} Loading Loading @@ -181,12 +181,11 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (!isset($this->weight) && ($roles = $storage->loadMultiple())) { if (!isset($this->weight)) { // Set a role weight to make this new role last. $max = array_reduce($roles, function ($max, $role) { return $max > $role->weight ? $max : $role->weight; }); $this->weight = $max + 1; $this->weight = array_reduce($storage->loadMultiple(), function ($max, $role) { return $max > $role->weight ? $max : $role->weight + 1; }, 0); } if (!$this->isSyncing() && $this->hasTrustedData()) { Loading Loading @@ -265,4 +264,19 @@ public function onDependencyRemoval(array $dependencies) { return $changed; } /** * Returns all valid permissions. * * @return string[] * All possible valid permissions. * * @see \Drupal\user\PermissionHandler::getPermissions() * * @internal * @todo Revisit in https://www.drupal.org/node/3446364 */ public static function getAllValidPermissions(): array { return array_keys(\Drupal::service('user.permissions')->getPermissions()); } } Loading
core/modules/config/tests/src/Functional/ConfigDraggableListBuilderTest.php +0 −10 Original line number Diff line number Diff line Loading @@ -59,16 +59,6 @@ public function testDraggableList(): void { $this->drupalGet('admin/people/roles'); $this->assertSession()->responseContains('<td>' . Html::escape($role_name)); // Make sure that NULL weights do not break the list builder. Use the // configuration API so that the value does not get type-casted according to // the configuration schema. \Drupal::configFactory() ->getEditable('user.role.role_0') ->set('weight', NULL) ->save(TRUE); $this->drupalGet('admin/people/roles'); $this->assertSession()->statusCodeEquals(200); } }
core/modules/jsonapi/tests/src/Functional/RoleTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -91,7 +91,7 @@ protected function getExpectedDocument() { 'status' => TRUE, 'dependencies' => [], 'label' => 'Llama', 'is_admin' => NULL, 'is_admin' => FALSE, 'permissions' => [], 'drupal_internal__id' => 'llama', ], Loading
core/modules/node/tests/src/Kernel/NodeAccessTestBase.php +1 −2 Original line number Diff line number Diff line Loading @@ -58,8 +58,7 @@ protected function setUp(): void { $this->installSchema('node', 'node_access'); $this->installEntitySchema('user'); $this->installEntitySchema('node'); $this->installConfig('filter'); $this->installConfig('node'); $this->installConfig(['filter', 'node', 'user']); $this->accessHandler = \Drupal::entityTypeManager()->getAccessControlHandler('node'); Loading
core/modules/user/config/schema/user.schema.yml +5 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,8 @@ user.flood: user.role.*: type: config_entity label: 'User role settings' constraints: FullyValidatable: ~ mapping: id: type: machine_name Loading @@ -143,6 +145,9 @@ user.role.*: sequence: type: string label: 'Permission' constraints: Callback: callback: [\Drupal\user\Entity\Role, getAllValidPermissions] action.configuration.user_add_role_action: type: mapping Loading
core/modules/user/src/Entity/Role.php +20 −6 Original line number Diff line number Diff line Loading @@ -88,7 +88,7 @@ class Role extends ConfigEntityBase implements RoleInterface { * * @var bool */ protected $is_admin; protected $is_admin = FALSE; /** * {@inheritdoc} Loading Loading @@ -181,12 +181,11 @@ public static function postLoad(EntityStorageInterface $storage, array &$entitie public function preSave(EntityStorageInterface $storage) { parent::preSave($storage); if (!isset($this->weight) && ($roles = $storage->loadMultiple())) { if (!isset($this->weight)) { // Set a role weight to make this new role last. $max = array_reduce($roles, function ($max, $role) { return $max > $role->weight ? $max : $role->weight; }); $this->weight = $max + 1; $this->weight = array_reduce($storage->loadMultiple(), function ($max, $role) { return $max > $role->weight ? $max : $role->weight + 1; }, 0); } if (!$this->isSyncing() && $this->hasTrustedData()) { Loading Loading @@ -265,4 +264,19 @@ public function onDependencyRemoval(array $dependencies) { return $changed; } /** * Returns all valid permissions. * * @return string[] * All possible valid permissions. * * @see \Drupal\user\PermissionHandler::getPermissions() * * @internal * @todo Revisit in https://www.drupal.org/node/3446364 */ public static function getAllValidPermissions(): array { return array_keys(\Drupal::service('user.permissions')->getPermissions()); } }