Widen type for $violations in EntityConstraintViolationList constructor

Created on 6 January 2025, about 2 months ago

Problem/Motivation

  /**
   * {@inheritdoc}
   *
   * @param \Drupal\Core\Entity\FieldableEntityInterface $entity
   *   The entity that has been validated.
   * @param array $violations
   *   The array of violations.
   */
  public function __construct(FieldableEntityInterface $entity, array $violations = []) {
    parent::__construct($violations);
    $this->entity = $entity;
  }

but the parent constructor takes an iterable, not an array:

    public function __construct(iterable $violations = [])

This means that when constructing a new EntityConstraintViolationList from an existing ConstraintViolationList you need to use iterator_to_array():

new EntityConstraintViolationList($entity, iterator_to_array($e->getConstraintViolationList()));

but it would be clearer to be able to just say

new EntityConstraintViolationList($entity, $e->getConstraintViolationList());

Steps to reproduce

Proposed resolution

Widen the type from array to iterable.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

📌 Task
Status

Active

Version

11.0 🔥

Component

entity system

Created by

🇬🇧United Kingdom longwave UK

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