Problem/Motivation

Follow up from #1845546-121: Implement validation for the TypedData API

Maybe also improve how we deal with multiple-bundle metadata here?

Steps to reproduce

N/A

Proposed resolution

See #20 + #23.

Remaining tasks

Determine if this change should be made see #1845546-121: Implement validation for the TypedData API and #35

User interface changes

None.

API changes

Passing a string value to the Bundle constraint's bundle option is no longer allowed; it triggers a deprecation in Drupal 10.3 and will trigger an error in Drupal 11.

Data model changes

None.

Release notes snippet

None.

CommentFileSizeAuthor
#16 1905620-16.patch2.52 KBwim leers

Issue fork drupal-1905620

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

fago’s picture

Issue tags: +Entity Field API

tagging

fago’s picture

Title: Make the bundle constraint option to enforce always an array. » Enforce the bundle constraint option to be always an array

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

smustgrave’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

If still a valid task wonder if the issue summary could be updated please.

wim leers’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Postponed (maintainer needs more info) » Needs review
Issue tags: +Entity validation, +validation, +@deprecated
Related issues: +#2820364: Entity + Field + Property validation constraints are processed in the incorrect order
StatusFileSize
new2.52 KB

I stumbled upon this from another issue.

This issue exists to address @effulgentsia's feedback at #1845546-121: Implement validation for the TypedData API and @fago argued at #1845546-122: Implement validation for the TypedData API it should be done in a follow-up. This is that follow-up.

But this issue predates us having solid strategies for making changes like that happen.

So … this must do a deprecation. Although AFAICT nothing in core is even using this anymore, with the exception of \Drupal\KernelTests\Core\Entity\BundleConstraintValidatorTest::assertValidation(). Not even \Drupal\Tests\Core\Plugin\Context\EntityContextDefinitionIsSatisfiedTest::providerTestIsSatisfiedByPassBundledEntity(). Let's find out!

Status: Needs review » Needs work

The last submitted patch, 16: 1905620-16.patch, failed testing. View results

wim leers’s picture

We could totally continue with #16 here.

But as I wrote at #3382581-12: Add new `EntityBundleExists` constraint:

  1. I did a review in which I tried to RTBC this. And in doing so, I discovered the existence of \Drupal\Core\Entity\Plugin\Validation\Constraint\BundleConstraint (introduced in #1845546: Implement validation for the TypedData API, with a follow-up that I just pushed forward after >10 years of silence: #1905620: Enforce the BundleConstraint "bundle" option to be always an array).

    I think we should document what the difference is between the (existing) Bundle and (new) BundleExists.

    AFAICT BundleConstraint should never have existed … it should just have used the Choice constraint instead?! It has existed since 2010, so it's not like it wasn't available 😅

… maybe the correct course of action here is to:

  1. Deprecate Bundle altogether and switch to Choice
  2. Alternatively, make Bundle an alias of Choice.

Note that Choice was explicitly added to Drupal core in #3373653: Add a `langcode` data type to config schema — lots of things in Drupal core already use it!

andypost’s picture

Curious how it will affect existing code which is using Bundle in block annotations

smustgrave’s picture

Status: Needs review » Needs work

Of the 2 options

1. Deprecate Bundle altogether and switch to Choice
2. Alternatively, make Bundle an alias of Choice.

Think 1 makes the most sense.

Making an alias even though it should cover backwards compatibility, think the idea of having 2 constraints around that do the same could be confusing to some.

wim leers’s picture

Assigned: fago » wim leers
Issue summary: View changes
Issue tags: +Configuration schema, +Needs change record

#3382581: Add new `EntityBundleExists` constraint landed!

#20: I agree. Except that the validation error message for Bundle kinda makes more sense. Still, let's find out how much change it would cause if we actually removed this constraint.

wim leers’s picture

Title: Enforce the bundle constraint option to be always an array » Enforce the BundleConstraint "bundle" option to be always an array
Assigned: wim leers » Unassigned
Priority: Normal » Minor
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs change record

In trying to do #21, I discovered I was wrong in #18. Choice works at the (property) value level. Bundle works at the entity object (EntityAdapter to be exact) level.

Change record created for just this tiny deprecation.

P.S.: @effulgentsia wrote #1845546-121: Implement validation for the TypedData API.1 (which triggered this issue) exactly 11 years ago today.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Ran test-only feature and got a failure, see https://git.drupalcode.org/issue/drupal-1905620/-/jobs/723178

Updated the CR slightly to include an example, for visual people like myself.

Code looks good to me.

wim leers’s picture

Thanks! The changes to the change record weren't quite accurate though, so fixed that. Please check it again and see if you like it? :)

catch’s picture

Status: Reviewed & tested by the community » Needs review

I think the deprecation here should probably be for 12.0.0 now unless we really need to drop it in 11.x per discussion in #3410492: Defer disruptive 10.3 deprecations for removal until 12.0.

wim leers’s picture

Is this truly disruptive? It's a trivial change that modules can make today and it'd work fine all the way back to Drupal 8? 🤔

P.S.: following that issue now — very interesting!

borisson_’s picture

I would like to move this back to RTBC and say this isn't truly disruptive, but I actually think it is, we don't know how custom entities look and for them they it would be a change.

Should be simple enough to just update the number in the deprecation

wim leers’s picture

Should be simple enough to just update the number in the deprecation

👍 Let's do that.

smustgrave’s picture

Status: Needs review » Needs work

Probably fine to self RTBC after that update.

catch’s picture

It's a trivial change that modules can make today and it'd work fine all the way back to Drupal 8?

This is very true, but if they're minimally/under-maintained and already have Drupal 11 compatible releases (or if they don't need any other changes other than .info.yml so far), then it's disruptive for sites trying to update to Drupal 11 and finding out modules aren't compatible. You only need one or two modules not ready to delay a site update, and those modules only need one or two small deprecations preventing a fully 11.x-compatible release to be the ones that cause the delay - so lots of small core deprecations can add up.

For internal stuff where the bc we add is 'best effort' anyway like constructor changes, we definitely shouldn't apply this, especially because multiple changes to the same constructor gets cumulatively harder to account for. But public API breaks where the bc layer is easy, I think it's nicer to do this for the few months before the major release - if it's likely to cause pain, we can always decide the other way.

wim leers’s picture

👍 Thanks for that extra context, @catch!

quietone made their first commit to this issue’s fork.

quietone’s picture

Status: Needs work » Needs review

Rebased and updated the deprecation notice.

longwave’s picture

I don't get why we need to do this. DX is slightly nicer if developers can pass a string in the simple case or an array of strings otherwise. Given it's been over 10 years since this was proposed are there better things to work on?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Regarding #35 believe that should be answered by committer team?

But looking at the MR believe all feedback has been addressed.

quietone’s picture

Issue summary: View changes

There is one question remaining, which is whether to do this or not. See the remaining tasks in the issue summary.

catch’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Agreed with #35, I think we should mark this 'by design' and just support a single bundle or an array. There's no justification given in the issue summary or in @effulgentsia's original comment which is just one sentence of a larger review.

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (works as designed)

This has been waiting for 7 months for a justification for this change. None has been given, so I am closing this issue.

If there is a reason to do this that has been missed, add an explanatory comment and set the status to 'Active'.