Problem/Motivation
The logic in taxonomy_entity_index_entity_update() contains a heap of great code and logic that can't be re-used.
Similarly there is no OO equivalent of taxonomy_entity_index_get_taxonomy_field_names
Proposed resolution
Provide an OO version of taxonomy_entity_index_get_taxonomy_field_names
Extract the logic out of taxonomy_entity_index_entity_update so that it can be reused by other modules.
Remaining tasks
Replace taxonomy_entity_index_get_taxonomy_field_names() with a service.
Move taxonomy_entity_index_entity_update() logic into a service.
User interface changes
n/a
API changes
taxonomy_entity_index_get_taxonomy_field_names() replaced with the taxonomy_entity_index.field_information service.
Data model changes
n/a
Release notes snippet
TBD
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | taxonomy_entity_index-n3109723-5.patch | 5.46 KB | damienmckenna |
| #4 | 3109723-4-do-not-test.patch | 5.4 KB | larowlan |
| #4 | 3109723-4-includes-3104318.patch | 33.96 KB | larowlan |
| #4 | 3109723-interdiff-4.txt | 469 bytes | larowlan |
| #3 | 3109723-3104318-combined.patch | 33.96 KB | larowlan |
Comments
Comment #2
larowlanComment #3
larowlane.g something like this for the field info
Could do similar for extracting the terms from an entity.
And then another for the db operations.
Comment #4
larowlantests paying for themself - here's the fix
Comment #5
damienmckennaRerolled. It seems like most of this was committed in #3104318: Create tests and a config schema for taxonomy_entity_index.settings.
Comment #7
damienmckennataxonomy_entity_index_entity_update() needs to be replaced next.
I updated the issue summary.
Which ones specifically?
Comment #8
damienmckennaThe test fails because the static cache in the FieldInformation service is not invalidated when the field is added.
Comment #9
damienmckennaIs this the problem?
Comment #10
damienmckennaNope, #9 is not the correct approach.
Comment #11
larowlanGreat work 🙌
I'd be keen to also add something to extract TID values from an entity too. Been running custom code for that on a few projects.
do we need the
entity-taxonomy-fields_prefix? we're only storing one thing in the cache and its per entity-typeWe can read this from the field storage definition as the target-type is a storage level setting, will likely mean we can avoid the
::getFieldDefinitionscall inside the two inner for each loops.\Drupal\Core\Entity\EntityFieldManager::getFieldStorageDefinitionscan be called outside both loops, and then if a$field_namekey exits, we can callthis will be 8.x-1.15 now (at least)
Comment #12
larowlanOh, right, I wrote the first version of the patch and said the same thing 🤦 three year ago 😂
Comment #13
damienmckennaThe module includes optional support for per-field index instead of per-entity-type. I have not dug into the logic behind it yet, but I suspect that's part of it.