Fix DataType::$constraint docs that reference method that does not exist

Created on 18 September 2017, about 7 years ago
Updated 4 August 2024, 3 months ago

Problem/Motivation

The DataType annotation documents $constraints and points people to the getConstraints() method that no longer exists on TypedDataManager. In fact the $constraints property on data types does not seem to be used in core as data definitions are used to add and enforce constraints. TypedData::getConstraints uses its definition's constraints rather than any provided on the annotation.

TypedDataInterface::getConstraints only explains that it should get constraints, and how it is done is left to the implementation so it is possible that a data type could implement constraint getting from the annotation.

Current documentation:

  /**
   * An array of validation constraints for this type.
   *
   * @var array
   *
   * @see \Drupal\Core\TypedData\TypedDataManager::getConstraints().
   */
  public $constraints;

This could be rolled into #2047119: Remove deprecated documentation in DataType annotation β†’ , but unsure of the scope of that issue as it is a follow-up to #2002102: Move TypedData primitive types to interfaces β†’ .

Proposed resolution

  • Clarify that $constraints is not used normally and remove the @see TypedDataManager::getConstraints(), and clarify that a data type uses constraints from its data definition by default.
    • Any additional explanation about implementing constraints or using $constraints property (if it isn't deprecated) should go on the Data Type Plugin docs page β†’ .
  • Decide whether or not to deprecate $constraints property on DataType annotation.

Remaining tasks

Need to decide approach to take.

User interface changes

N/A

API changes

Yes, If we deprecate $constraints property in the annotation, then it will be removed in a later version.

Data model changes

N/A

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
Typed dataΒ  β†’

Last updated 5 days ago

  • Maintained by
  • πŸ‡¦πŸ‡ΉAustria @fago
Created by

πŸ‡ΊπŸ‡ΈUnited States mradcliffe USA

Live updates comments and jobs are added and updated live.
  • Documentation

    Primarily changes documentation, not code. For Drupal core issues, select the Documentation component instead of using this tag. In general, component selection is preferred over tag selection.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024