Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
I was just wondering why there isn't a TranslatedNodeProcessor, just like the TranslatedTermProcessor. Figured that it could not be that hard, so I created one and tested it. Works like a charm!
But please, review my patch and will happily apply your feedback.
Comment | File | Size | Author |
---|---|---|---|
#42 | interdiff.txt | 1.9 KB | lammensj |
#42 | add-2752583-42.patch | 18.08 KB | lammensj |
Comments
Comment #2
borisson_Hi Jasper,
I found a couple of things that are not up to the drupal standards, I fixed those myself in the attached patch. We'll be committing a few issues today, and I think this'll get in as well. Thanks for the patch!
Comment #5
borisson_@LammensJ, because the test was no in the correct namespace earlier, it wasn't executed. Can you fix the test fails?
Comment #6
lammensj CreditAttribution: lammensj at iO commentedYep, my bad.
Comment #9
lammensj CreditAttribution: lammensj at iO commented*grmmbl* Drupal using its own deprecated functions... *grmmbl*
Comment #12
lammensj CreditAttribution: lammensj at iO commentedHad some problems with PHPUnit on my laptop. Tests are successful now :)
Comment #13
borisson_Awesome, thanks!
Comment #14
borisson_Can we change the current taxonomy term processor to an entity processor and use entity::load instead? If possible useing loadMultiple as well to have less individual loads.
Comment #15
lammensj CreditAttribution: lammensj at iO commentedThe patch includes the all new TranslateEntityProcessor. I didn't replace the previous ones just yet because I'm not sure if this implementation is the way to go... The processor requires that you specify the entity type when selecting it. I needed to add that because EntityTypeManager->loadMultiple asks for one. Makes sense if you think about it, but it was rather hard to find a way to provide this.
I could have loaded the index and retrieved it from there. That should have been the solution in D7, but not in D8 where you can select multiple types of datasource. In other words, take a look at the file and tell me what you think.
Comment #16
Nick_vhYou can actually find it through the index. Since a field cannot be shared across entity types you can look up the entity type in the storage of the field.
So: facet processor -> datasource -> index -> field -> storage -> fetch entity type. Unless I'm missing something here? Discussed this briefly with drunkenmonkey and borisson
Comment #17
lammensj CreditAttribution: lammensj at iO commentedHi Nick!
I did look in that direction before switching to the configuration form solution. It's just that when you call $facet->getFacetSource(), it will return a FacetSourcePluginInterface object. Can we be sure that this will always be a View?
Comment #18
borisson_It won't always be a view, we also support drupal core and search_api_page as facet sources, they don't have that.
Comment #19
lammensj CreditAttribution: lammensj at iO commentedThat's what I was thinking... Anyway, the interdiff will show the proposed solution to find the entity type and it works :)
Comment #20
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedHadn't seen this issue so I made another try at this in https://www.drupal.org/node/2760401.
I made some small tweaks to #20:
- added . at the end of a comment
- load entity_type the same way as in ListItemProcessor::build()
- don't set setDisplayValue twice
Quick questions though: why do we have three processors (entity, node, term) while they're all entities?
Comment #21
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #22
borisson_That makes sense, it should be sufficient if we only have an entity processor.
Comment #23
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #24
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #27
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedGuess I'll have to mock the language_manager and entity_type.manager aswell.
Comment #28
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedInjected services:
- language_manager
- entity_type.manager
WIP, still needs testing.
Comment #29
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedMocking all dependencies is tricky. But I noticed $source->getIndex() is based upon SearchApiFacetSourceInterface and thus only available for SearchApiViews, correct?
Comment #30
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #31
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedComment #32
borisson_I fixed some coding style things and added extra documentation.
This looks great overall. I'd love to hear from @LammensJ if this also works in his usecase, if it does, we can commit this.
Comment #33
mpp CreditAttribution: mpp as a volunteer and at AmeXio commentedThanks for the review!
Comment #34
lammensj CreditAttribution: lammensj at iO commentedToo bad we have to rely on the SearchApiFacetSourceInterface class to get the entity type. I guess that's an api change in Search Api if we want to remove that if. @borisson_, @Nick_vh, correct me if I'm wrong.
I also removed the switch-statement for rendering the title. Since every term or node descends from the Entity class, we can just use $object->label().
Furthermore, it works in my use case. No errors and no warning, so good job!
Comment #37
borisson_That is too bad, I agree. But this is not because of search api, but because we also support creating facets for drupal core. And because core's search doesn't have an "index" concept we have write the check.
I'll have a look at the test-failures tonight and when those are resolved, we can commit this. Thanks for the review and for removing the switch @LammensJ, that looks great!
Comment #38
lammensj CreditAttribution: lammensj at iO commentedThe tests broke because of the getTitle- and getName-usages which were removed.
Comment #39
lammensj CreditAttribution: lammensj at iO commentedComment #42
lammensj CreditAttribution: lammensj at iO commentedWrong patch source, my bad.
Comment #43
lammensj CreditAttribution: lammensj at iO commentedComment #44
borisson_Awesome, committing this later today.
Comment #46
borisson_Committed, thanks everyone!