Updated: Comment #0
Problem/Motivation
There's too much Field classes in core now so it's hard to use them:
- use statement could have collisions (primary for \Drupal\Core\Entity\Field\Field
- DX confusion, only a wrapper for single function
- used only for purpose Field::fieldInfo()
Some name conflicts would be resolved in #2051923: Rename \Drupal\Core\Entity\Field\Field, related subclasses and interfaces to *FieldItemList
Proposed resolution
Replace wrapped function class with \Drupal::service('field.info')->fieldInfo()
Use proper injection of 'field.info' service for controllers and services
Use $this->container->get('field.info') for tests
$ git grep '::fieldInfo'
core/lib/Drupal/Core/Entity/Query/Sql/Tables.php:61: $field_info = FieldInfo::fieldInfo();
core/modules/content_translation/lib/Drupal/content_translation/Form/TranslatableForm.php:84: $this->fieldInfo = FieldInfo::fieldInfo()->getField($entity_type, $field
core/modules/editor/editor.module:544: $settings = Field::fieldInfo()
core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php:92: $this->field = Field::fieldInfo()->getField($this->entityType, $this-
core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceFieldTest.php:93: $instances = Field::fieldInfo()->getBundleInstances($this->entityType
core/modules/field/field.deprecated.inc:186: * Field::fieldInfo()->getFieldMap().
core/modules/field/field.deprecated.inc:189: return Field::fieldInfo()->getFieldMap();
core/modules/field/field.deprecated.inc:212: * Field::fieldInfo()->getField($field_name).
core/modules/field/field.deprecated.inc:215: return Field::fieldInfo()->getField($entity_type, $field_name);
core/modules/field/field.deprecated.inc:233: * Field::fieldInfo()->getFieldById($field_id).
core/modules/field/field.deprecated.inc:236: return Field::fieldInfo()->getFieldById($field_id);
core/modules/field/field.deprecated.inc:258: * Field::fieldInfo()->getFields().
core/modules/field/field.deprecated.inc:261: return Field::fieldInfo()->getFields();
core/modules/field/field.deprecated.inc:290: * Field::fieldInfo()->getInstances(),
core/modules/field/field.deprecated.inc:291: * Field::fieldInfo()->getInstances($entity_type) or
core/modules/field/field.deprecated.inc:292: * Field::fieldInfo()->getBundleInstances($entity_type, $bundle_name).
core/modules/field/field.deprecated.inc:295: $cache = Field::fieldInfo();
core/modules/field/field.deprecated.inc:327: * Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name).
core/modules/field/field.deprecated.inc:330: return Field::fieldInfo()->getInstance($entity_type, $bundle_name, $field_name);
core/modules/field/field.info.inc:44: Field::fieldInfo()->flush();
core/modules/field/field.info.inc:88: return array_filter(Field::fieldInfo()->getFields(), function ($field) {
core/modules/field/field.info.inc:147: $info = Field::fieldInfo()->getBundleExtraFields($entity_type, $bundle);
core/modules/field/lib/Drupal/field/Plugin/Type/FieldType/ConfigField.php:42: $instances = FieldAPI::fieldInfo()->getBundleInstances($entity->entityType(), $entity-
core/modules/field/lib/Drupal/field/Tests/FieldImportCreateTest.php:64: $instances = Field::fieldInfo()->getInstances('entity_test');
core/modules/forum/forum.module:159: $field = Field::fieldInfo()->getField('node', 'taxonomy_forums');
Remaining tasks
approve api clean-up
file change notice
update existing change notices
User interface changes
no
API changes
removal of Drupal\field\Field
not widely used
Related Issues
#2051923: Rename \Drupal\Core\Entity\Field\Field, related subclasses and interfaces to *FieldItemList
#2089853: TranslatableForm totally broken
#1875086: Improve DX of drupal_container()->get()
#1961548: [Policy, no patch] Decide how the module-specific services are made available as static methods (similar to \Drupal::$service())
#1950088: Move FieldInfo class to the DIC
Comment | File | Size | Author |
---|---|---|---|
#15 | interdiff.txt | 10.14 KB | andypost |
#15 | drupal8.field-system.2089807-15.patch | 12.74 KB | andypost |
#12 | drupal8.field-system.2089807-10.patch | 12.49 KB | andypost |
#8 | drupal8.field-system.2089807-8.patch | 12.36 KB | andypost |
#4 | interdiff.txt | 10.65 KB | andypost |
Comments
Comment #1
BerdirNot sure but you should grep for Field::fieldInfo, a lot of the Field:: stuff is something else.
Comment #2
andypostThat's all usage
Comment #3.0
(not verified) CreditAttribution: commentedUpdated issue summary.
Comment #4
andypostright patch
Comment #4.0
andypostUpdated issue summary.
Comment #5
andypostDiscussed with alexpott in IRC
Comment #6
BerdirThe problem is that this *is* the pattern that was defined when the Drupal class was added. I already tried to point out back then that it has a high risk for duplicate class names or back then even clashes (as entity classes were in the main namespace, not /Entity).
Views for example has such a class too (Views), it's cheating a bit because the module name is plural and the entity type is singular, but it's close enough too.
So this isn't just about removing that class, this is just following a defined pattern. It's about changing that pattern.
Comment #7
yched CreditAttribution: yched commented@Berdir +1
And I tried to make those exact same arguments too :-)
Comment #8
andypostSo let's rename it to Fields at least, namespace protects the class from clashes for contrib
Comment #9
andypostSuppose better title
Comment #11
BerdirNo, that's not what I meant :)
field.module => Field.php
view*s*.module => Views.php
Fields.php is not following the defined pattern.
I'd rather see something like FieldService(s) and ViewsService(s), but I also argued for \Drupal\Core\Service(s) instead of \Drupal ;)
Comment #12
andypostnow file renamed too
Comment #13
andypostSo maybe better rename it to FieldInfo()::fieldInfo()?
Comment #14
yched CreditAttribution: yched commentedFieldInfo::fieldInfo() looks like a WTF and doesn't work when we find out we need to add more services in field.module.
I stick with @Berdir, FieldService(s) / ViewsService(s) +1 on principle, but yeah no way to be consistent with \Drupal :-(
Comment #15
andypostRe-rolled for FieldService also changed doc-block
Comment #15.0
andypostUpdated issue summary.
Comment #16
David_Rothstein CreditAttribution: David_Rothstein commentedAnother option might be FieldModule::fieldInfo()? I think it's more descriptive, and wouldn't be inconsistent with \Drupal since Drupal is not a module...
Comment #17
yched CreditAttribution: yched commented#16: why not - works in the sense its less inconsistent with \Drupal. It remains quite obscure as to what the class is useful for, but I guess that's also true of \Drupal, so...
Also, we're not just discussing field.module here, this about a policy across core and contrib modules, so the discussion and proposals
should happen in #1961548: [Policy, no patch] Decide how the module-specific services are made available as static methods (similar to \Drupal::$service()) (which already contains arguments about why the current policy sucks). Copied the above over there, and postponing this issue on that other one.
Comment #17.0
yched CreditAttribution: yched commentedadded history to related issues
Comment #18
andypostFixed in #2167167: Remove field_info_*()