The error message showing the field machine name which is not user friendly. In fact, the field label could be in a different language.
Here is an example how to change the error message. (For a node validation).

+$fieldInfo = \Drupal\field\Entity\FieldConfig::loadByName('node', $form['bundle'], $field_name);
+$fieldLabel = $fieldInfo->getLabel();
-$form_state->setErrorByName($field_name, t('The field @field_name has to be unique.', array('@field_name' => $field_name)));
+$form_state->setErrorByName($field_name, t('The field @field_name has to be unique.', array('@field_name' => $fieldLabel)));

Comments

taitai created an issue. See original summary.

alex_optim’s picture

Assigned: Unassigned » alex_optim
tucho’s picture

Status: Active » Closed (duplicate)
Related issues: +#2893816: Show field label instead of field name