FieldTypePluginManager::createInstance() produces warnings unless fed dummy options

Created on 12 April 2018, over 6 years ago
Updated 13 June 2023, over 1 year ago

According to its docs:

> * Creates a field item, which is not part of an entity or field item list.

However:

  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  $instance = $field_type_manager->createInstance($my_type, ['field_definition' => $my_field]);

produces warnings from TypedDataManager for missing 'name' and 'parent' properties, because of:

  public function create(DataDefinitionInterface $definition, $value = NULL, $name = NULL, $parent = NULL) {
    $typed_data = $this->createInstance($definition->getDataType(), [
      'data_definition' => $definition,
      'name' => $name,
      'parent' => $parent,
    ]);

The workaround is to pass in some NULLs:

  $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
  $instance = $field_type_manager->createInstance($type, ['field_definition' => $state_field, 'name' => NULL, 'parent' => NULL]);

FieldTypePluginManager should take care of this.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 6 days ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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