Problem/Motivation

There are a couple of field validator functions in LinkWidget:

  • validateTitleElement() - "@title field is required if there is @uri input."
  • validateTitleNoLink() - The @uri field is required when the @title field is specified.
  • Proposed resolution

    Move the validateTitleElement() validation into a constraint, so it works in other contexts.

    Ignore the validateTitleNoLink() validation. It must remain as a form-level validator. See comment #12. I'm leaving this information in the issue summary so no one wonders "Why not move both validation functions?"

    Remaining tasks

    Review. Feedback. Commit.

    User interface changes

    API changes

    LinkWidget::validateTitleElement() will be deprecated.

    Data model changes

    Release notes snippet

Issue fork drupal-3093118

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Sam152 created an issue. See original summary.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

dcam’s picture

Title: Move validation from LinkWidget into a constraint » [PP-1] Move validation from LinkWidget into a constraint
Status: Active » Postponed

I started working on this, but realized it's postponed on #3077149: Duplicate inline form errors in external Link widgets because we need the fix for inline form errors to be integrated into the validators.

dcam’s picture

Title: [PP-1] Move validation from LinkWidget into a constraint » Move validation from LinkWidget into a constraint
Status: Postponed » Active

This is unblocked.

dcam’s picture

Title: Move validation from LinkWidget into a constraint » Move link title validation from LinkWidget into a constraint
Issue summary: View changes
Status: Active » Needs review

I'm removing the change to the "The @uri field is required when the @title field is specified" validation from the issue. I tried writing a constraint validator for it, but it didn't work. The reason why is because the isEmpty() validation kicks in before the constraint validation. So if the URI is empty and the title is not, then Drupal simply thinks the whole field is empty and never checks any constraints. As far as I can tell, this has to remain as a form-level validation.

dcam’s picture

Issue summary: View changes

I realized that we need to deprecate LinkWidget::validateTitleElement() instead of deleting it.

smustgrave’s picture

Question is there a way to call the constraint from the deprecated function? So we know it's a 1 to 1 replacement?

dcam’s picture

@smustgrave I don't think so. The constraint validator seems incompatible with form validation as far as I can tell. Did you have any thoughts about how?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems like a good deprecation and update

  • catch committed d9515b49 on 11.x
    task: #3093118 Move link title validation from LinkWidget into a...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 11.x, thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.