The DataDefinitionInterface is missing setConstraints method

Created on 4 November 2016, about 8 years ago
Updated 7 February 2023, almost 2 years ago

Problem/Motivation

The interface \Drupal\Core\TypedData\DataDefinitionInterface is missing the setConstraints() method that is defined in the \Drupal\Core\TypedData\DataDefinition::setConstraints even with the {@inheritdoc} tag. The method is present in the \Drupal\Core\Field\FieldConfigInterface::setConstraints for example, and I think it should be moved to the DataDefinitionInterface instead.

Allowing modules to overwrite the constraints of TypedData with the setConstraints method (instead of adding a constraint through addConstraint) seems like a valid use case.

An example of this is in \Drupal\Core\Field\FieldConfigBase

  /**
   * {@inheritdoc}
   */
  public function setPropertyConstraints($name, array $constraints) {
    $item_constraints = $this->getItemDefinition()->getConstraints();
    $item_constraints['ComplexData'][$name] = $constraints;
    $this->getItemDefinition()->setConstraints($item_constraints);
    return $this;
  }

Proposed resolution

Add the setConstraints method to \Drupal\Core\TypedData\DataDefinitionInterface.

Remaining tasks

Add the setConstraints method to \Drupal\Core\TypedData\DataDefinitionInterface.
Remove the setConstraints method from \Drupal\Core\Field\FieldConfigInterface::setConstraints

User interface changes

None

API changes

\Drupal\Core\TypedData\DataDefinitionInterface

Data model changes

None

πŸ“Œ Task
Status

Needs work

Version

10.1 ✨

Component
Typed dataΒ  β†’

Last updated 16 days ago

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

Live updates comments and jobs are added and updated live.
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