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.
Comment | File | Size | Author |
---|---|---|---|
#15 | 2960339-nr-bot.txt | 2.92 KB | needs-review-queue-bot |
Issue fork drupal-2960339
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #14
jodavidson CreditAttribution: jodavidson as a volunteer commentedConfirmed that TypedDataManager::createInstance() does not gracefully handle the missing name and parent parameters.
Added some code to set those elements of the array if not present.
Comment #15
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #16
jodavidson CreditAttribution: jodavidson as a volunteer commentedUnfortunately my coded editor respected the Symfony standard rather than the Drupal one. Oops. Fixed and re-pushed.
Comment #17
smustgrave CreditAttribution: smustgrave at Mobomo commentedCan the issue summary be updated to highlight the proposed solution.
Also as a bug will need a test case to show the issue.
Comment #18
joachim CreditAttribution: joachim as a volunteer commented> Can the issue summary be updated to highlight the proposed solution.
It's this:
> FieldTypePluginManager should take care of this.