Change record status: 
Introduced in branch: 
2.1.x
Introduced in version: 
2.1.1-beta1
Description: 

The purpose of UserRestrictionType plugins is no longer to match the submitted data with the pattern used in a user restriction entity, but to build the data to match with the pattern used in a user restriction entity. As consequence, they do no longer need to implement UserRestrictionTypeInterface::matches() but UserRestrictionTypeInterface::buildData().

Examples

public function buildData(array $form, FormStateInterface $form_state, string $form_id, string $type = 'string'): string|object|null {
  $email = $form_state->getValue('mail');

  $this->setErrorMessage($this->t(
    'The email %mail is reserved, and cannot be used.',
    ['%mail' => $email]
  ));

  return match($type) {
    'object' => (object) ['mail' => $email],
    'string' => $email,
    default => NULL,
  };
}
public function buildData(array $form, FormStateInterface $form_state, string $form_id, string $type = 'string'): string|object|null {
  $client_ip = $this->requestStack->getCurrentRequest()->getClientIp();

  $this->setErrorMessage($this->t(
    'Accessing the site from the IP %value is not allowed.',
    ['%value' => $client_ip]
  ));

  return match($type) {
    'object' => (object) ['ip' => $client_ip],
    'string' => $client_ip,
    default => NULL,
  };
}
Impacts: 
Module developers
Site templates, recipes and distribution developers