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

UserRestrictionType plugins that extend UserRestrictionTypeBase need to call ::setLogMessage() and ::setErrorMessage() to set the logged message and the message shown as form validation error. This is usually done inside ::buildData().

Example code

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

  $this->setLogMessage([
    'Restricted name %name matching %restriction has been blocked.',
    ['%name' => $name],
  ]);
  $this->setErrorMessage($this->t(
    'The name %name is reserved, and cannot be used.',
    ['%name' => $name]
  ));

  return match($type) {
    'object' => (object) ['name' => $name],
    'string' => $name,
    default => NULL,
  };
}

UserRestrictionType plugins that do not extend UserRestrictionTypeBase do not need to call those methods, but need to store in a class property either the messages which will be returned by ::getLogMessage() and ::getErrorMessage()or the values used to build those messages.

Impacts: 
Module developers
Site templates, recipes and distribution developers