Check of $value not covering LinkItem cases in link contraint validators

Created on 13 September 2023, about 2 years ago

Problem/Motivation

In certain cases, the $value parameter passed into the validators inside core/modules/link/src/Plugin/Validation/Constraint seems to be an instance of LinkItemInterface. All these validators check if the value is actually set using the following condition:

  public function validate($value, Constraint $constraint) {
    if (isset($value)) {

In the case of an LinkItem with an empty value of its uri main property this check above will pass, even though the LinkItem->getEmpty() would return FALSE. This is weird and will lead to notices like the following in case the a LinkItem with an empty uri is passed in because of the $value->getUrl(); statement further below for example in \Drupal\link\Plugin\Validation\Constraint\LinkAccessConstraintValidator::validate():

Deprecated function: preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated in Drupal\Core\Url::fromUri() (line 281 of core/lib/Drupal/Core/Url.php).

This is sort of related to the discussion in https://www.drupal.org/project/drupal/issues/3262935#comment-15005255 ๐Ÿ“Œ Link field validation constraints don't give enough detail Needs work

Steps to reproduce

See steps in https://www.drupal.org/project/drupal/issues/3348390#comment-15228424 ๐Ÿ“Œ Improve the way entity forms are "disabled" early when an entity is being edited in a workspace Needs work as long as that patch is not applied/committed.

Proposed resolution

Check if the value passed in is LinkItemInterface instance and if that is empty skip the validation.

๐Ÿ› Bug report
Status

Active

Version

10.1 โœจ

Component
Linkย  โ†’

Last updated about 1 month ago

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024