ListDataDefinition::toArray is missing the data type

Created on 16 December 2021, about 3 years ago
Updated 21 August 2023, over 1 year ago

Problem/Motivation

The ListDataDefinition hardcodes its data type to list. However, it never pushes that to its internal definition that is exported with toArray.

Steps to reproduce

ListDataDefinition::createFromItemType('string')
          ->setRequired(TRUE)

When calling toArray the result is expected to be:

Array (
    'type' => 'list'
    'required' => true
)

But it is

Array (
    'required' => true
)

Proposed resolution

When a ListDataDefinition is created, set the `type` in the definition.

  /**
   * {@inheritdoc}
   */
  public function __construct(array $values = [], DataDefinitionInterface $item_definition = NULL) {
    $this->definition = $values;

Hard code it here or elsewhere. It's usually constructed with an empty array for values

  /**
   * {@inheritdoc}
   */
  public static function createFromItemType($item_type) {
    return new static([], \Drupal::typedDataManager()->createDataDefinition($item_type));
  }

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Needs work

Version

11.0 🔥

Component
Typed data 

Last updated 16 days ago

  • Maintained by
  • 🇦🇹Austria @fago
Created by

🇺🇸United States mglaman WI, USA

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