- Add Drupal\field\FieldInfo as a 'field.info' service in field.services.yml
- Go over the FieldInfo class, collect all its service dependencies (entity manager, module handler, state...), add them as __construct() params, and as parameters in the yml service definition.
- Provide friendly access to the service through a Field::fieldInfo() static method
(discussion about the exact name of the helper class is taking place in #1961548: [Policy, no patch] Decide how the module-specific services are made available as static methods (similar to \Drupal::$service()), but that's not a blocker to get this started)
- Replace calls to _field_info_field_cache()
by Field::fieldInfo()
, and remove the function.
No need to remove the other field_info_*() functions for now, we'll remove them progressively.
Comment | File | Size | Author |
---|---|---|---|
#9 | 1950088-follow-up-9.patch | 945 bytes | andypost |
#6 | field-info-service-1950088-6.patch | 13.21 KB | swentel |
#6 | interdiff.txt | 809 bytes | swentel |
#4 | field-info-service-1950088-4.patch | 13.25 KB | swentel |
Comments
Comment #1
yched CreditAttribution: yched commentedMoving this to the core queue.
Having a Field::fieldInfo() method available soon would let us replace a large amount of the field_info_*() calls while we go over code that accesses $field and $instance definition structures in #1953408: Remove ArrayAccess BC layer from field config entities.
Would also provide a landing place for whatever comes out of #1953414: Move logic of field_read_fields() and field_read_instances() to the storage controller..
In short, it would be a good time to do this :-).
Any takers ? :-)
Comment #1.0
yched CreditAttribution: yched commentedAdded task summary
Comment #1.1
yched CreditAttribution: yched commentedunclutter
Comment #2
yched CreditAttribution: yched commentedfix title
Comment #3
yched CreditAttribution: yched commentedUpdated summary to point to #1961548: [Policy, no patch] Decide how the module-specific services are made available as static methods (similar to \Drupal::$service()) for the Field::fieldInfo() bit.
Comment #4
swentel CreditAttribution: swentel commentedLet's see how this behaves
Comment #5
yched CreditAttribution: yched commentedYay !
Nitpicks :-):
"statically persisted through the request by Field::FieldInfo".
Not really. Maybe skip this entire paragraph ? I don't think other services bother explaining their relation to the DIC and helper static methods.
Do we really need the ".. to use" prefixes ? Sounds a bit boilerplate.
(same in __construct() phpdoc)
Similar use cases in core use both $this->cachebackend or $this->cache, but the latter seems a bit more common.
Brevity++ ?
Maybe just "The module manager." ?
Comment #6
swentel CreditAttribution: swentel commentedYeah, I basically copy/pasted a lot from the Views class - which why it went relatively fast and exceptionally worked on a first try :)
New patch, only removed the paragraph for now, maybe a follow up to make sure both classes are standardized ?
Comment #7
yched CreditAttribution: yched commentedWorks for me.
Comment #8
webchickOnce again this looks like fine DX-cleanup, but please don't mark these patches as "major" when they're simple refactoring.
Committed and pushed to 8.x. Thanks!
Comment #8.0
webchickUpdate issue link
Comment #9
andypostThere's a test that now gets random failures
Settings are changes in child process and entity_info_cache_clear() has no effect on field_info_cache
Comment #10
BerdirI've actually seen this happening in other tests as well, fixed that at least twice.
What I did was simply adding a field_info_cache_clear() above it and say "clear the cache" instead of skipping it. While that's a tiny bit slower, it's a typical pattern in tests I think.
Comment #11
swentel CreditAttribution: swentel commentedIs this still valid, I'm pretty sure the random failure wasn't introduced by this one, so I think it's valid to close this no ?
Comment #12
swentel CreditAttribution: swentel commentedI'm going to close this, talked this through with alexpott as well. Ran the test 70 times with --repeat option and no single failure. We have seen it before the move to a service as well.
If there are random failures, file a new one, it's easier to keep track than follow ups.
Comment #14
andypostFollow-up #2089807: Rename Field::fieldInfo() to FieldService::fieldInfo() for better DX
Comment #14.0
andypostbolder changes