This answer links to a list of all possible types that can be used with DataDefinition::create().

One plugin that can be used is ItemList.

But I can't find any documentation on how to define what items are on the list.

I would have expected something like this:

$status_definition = DataDefinition::create('list')
  ->setLabel(new TranslatableMarkup('Status'))
    1 => 'One',
    2 => 'Two',
    3 => 'Three',

But the method setListItems (or anything similar) does not exist.

For some more context I'm following this article on how to extend the entity reference field type but instead of adding an integer field I want to add a list field.

1 Answer 1


ItemList is a generic base class. List is used here in the context of multivalued field items. Because Drupal has no separate class for single value fields (they are multivalued fields restricted to one value), this generic list data type is used in all Drupal fields.

When you look at the list of field types


you'll find ListStringItem, where List is used in the context you are probably looking for and you can use this as an example for this kind of field types implementing OptionsProviderInterface.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.