Closed (fixed)
Project:
User Restrictions
Version:
2.1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Oct 2025 at 11:03 UTC
Updated:
30 Oct 2025 at 20:44 UTC
Jump to comment: Most recent
UserRestrictionsFormBase::validationForm() contains the following code.
// Check for duplicate pattern.
$existing = $this->entityTypeManager
->getStorage('user_restriction')
->loadByProperties([
'rule_type' => $form_state->getValue('rule_type'),
'pattern' => $form_state->getValue('pattern'),
]);
/** @var \Drupal\Core\Entity\EntityFormInterface $form_object */
$form_object = $form_state->getFormObject();
if ($original_id = $form_object->getEntity()->getOriginalId()) {
unset($existing[$original_id]);
}
The code can be optimized, and search for restrictions with an ID that is different from the ID used by the edited restriction, which use the same pattern and the same rule type.
There is no need to check the original ID, since the ID cannot be changed after the restriction has been saved.
Replace that code with the following one.
$query = $this->entityTypeManager->getStorage('user_restriction')
->getQuery()
->accessCheck(FALSE)
->condition('id', $form_state->getValue('id'), '<>')
->condition('rule_type', $form_state->getValue('rule_type'))
->condition('pattern', $form_state->getValue('pattern'));
$existing = $query->execute();
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
avpadernoComment #3
avpadernoComment #4
avpadernoComment #6
avpadernoComment #7
avpadernoComment #9
avpadernoComment #12
avpaderno