Problem/Motivation
The LinkWidget
validation callback error messages do not include the field name. If an entity form has multiple Link fields, then it may be difficult to tell which instance had the error.
Steps to reproduce
These steps will trigger one of the three validation callbacks, specifically the one for bad internal paths.
- Add two Link fields to any content type.
- Configure the Link fields to allow internal paths.
- Create a new instance of the content type. Add any garbage input like a random character string to the Link fields.
- Attempt to save the content.
Note that there is only one error message even though both fields triggered the error. The error message does not contain the name of either field. The user must search through the form to find the triggering fields.
Proposed resolution
The error messages in the LinkWidget
validation callback functions should be updated to include the field name. The callbacks include:
validateUriElement()
validateTitleElement()
validateTitleNoLink()
You can use core/lib/Drupal/Core/Field/Plugin/Field/FieldWidget/OptionsWidgetBase.php
as an example. That widget includes the field name in its validation callback. We will take that as a best practice.
Remaining tasks
- Write a new MR.
- Review.
- Commit.
User interface changes
Updated LinkWidget
validation error messages.