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.
The new addition to the list value processor has a problem when the field that is trying to be translated is a search_api Item Field as the getSetting()
function does not exist,
Error: Call to undefined method Drupal\\search_api\\Item\\Field::getSetting() in /var/www/build/html/modules/contrib/facets/src/Plugin/facets/processor/ListItemProcessor.php on line 119
The following patch checks if the Field is a instance of search_api Item field and if so does not make the function call to getSetting()
Comment | File | Size | Author |
---|---|---|---|
#69 | using_the_list_value-2773113-69.patch | 16.42 KB | borisson_ |
#3 | Screen Shot 2016-07-26 at 9.22.13 PM.png | 25.65 KB | ndrake86 |
#3 | Screen Shot 2016-07-26 at 9.22.28 PM.png | 22.18 KB | ndrake86 |
Comments
Comment #2
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedComment #3
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedCouple of SC of the before and after.
Comment #4
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedIt was recommend that I use the interface instead of the referencing the Search API field Item directly so this is an updated patch with that change.
Comment #5
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedI think the other option is a patch the Search API that adds getSetting function call but I do not know if that is something that is even wanted for the Search API.
Comment #6
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedFrom drunken monkey in the search API issue #2773665: Add the getSetting function to Search API Item field
I don't quite understand how sometimes it changes or where the bug might be and with some help pointing the way I would have no problem working on fixing it.
Comment #7
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedChanging the title to be more descriptive of the problem.
Comment #8
borisson_I guess this makes sense, no idea why this happens though, do you think it's possible to provide a test?
Comment #9
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commented@borisson_ Sorry for the delay. I will put together a test patch for the issue when I have a bit of free time. But just to layout the general scenario.
Facet on Content Type.
page
Basic Page
Comment #10
borisson_@ndrake86: oh, don't worry, you can take all the time you need :) I'm currently focused on #2794745: Use Search API's display plugin to fix facets
Comment #11
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commented@borrison_ here is a first go at a webtest for the processor. Let me know your thoughts. This is actually the first time I have written a test so if bare with me as I figure this stuff all out.
Comment #12
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedComment #13
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedSmall changes trying to get this simpletests to work.
Comment #18
borisson_This needs a docblock.
Not sure what this is supposed to be, but I guess this should be removed?
Comment #19
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedSome of the code review changes from #18 for the test branch.
Comment #20
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedComment #21
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedWrong patch. My bad.
Comment #22
borisson_Can you rename the file to .patch, so the testbot can pick it up?
Comment #23
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedRe-roll to the tests patch as I realized I was a bit behind and the fix all in one patch.
Comment #24
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedborrison_, just saw the comment. Sorry about the patch names I thought as it was a test only patch you wouldn't want the test bot to pick it up. I did however re-roll the patch and test into one patch. Let me know if there is anything else I can do for this guy and thanks for reviewing.
Comment #27
borisson_I changed some docs around. I think the fails here are not specific to this issue but rather related to something else, I just committed something that should fix this.
Comment #28
borisson_Comment #31
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedI am not sure exactly with this is failing still. The test looks correct? Did I miss anything when creating it?
Comment #32
borisson_I'll have a look at the tests tonight.
Comment #33
andypostCore provides interface
\Drupal\Core\TypedData\OptionsProviderInterface
that should be usedHere should be check for \Drupal\Core\TypedData\OptionsProviderInterface
and it's methods used instead of direct settings access
Comment #34
YurkinPark CreditAttribution: YurkinPark at Skilld commentedDidn't find a solution with
\Drupal\Core\TypedData\OptionsProviderInterface
, but covered many case with this patch.Comment #35
borisson_Setting to needs review for the testbot, not sure if that's the way to go though. At least we should also implement the integration test from #27.
The patch in #34 makes this already very unreadable / complex method even worse, I'm not too happy with that - but that might be fixed in a follow-up.
@andypost: the optionsProvider might be a good thing to do here - getPossibleOptions on that interface does look like what we need.
Comment #38
andypostI debugged that a bit, and here's another bug - instead of
$field_identifier
(that is index related) you should use$index->getField($field_identifier)->propertyPath
Because mapping to fields should be done through typed data, without property path a lot of errors possible caused by name collisions
For example Node has field *labels* and Node attache Term has field *labels* - facet will try to use node field but should take property path in account
Comment #39
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commented@_borrison, what are we still looking for on this? Any ideas about
\Drupal\Core\TypedData\OptionsProviderInterface
I am not to sure what @andypost was mentioning. I have some time this week if you have a suggestion on where to start.Comment #40
borisson_We're looking for a solution based on #27 (as that has tests + the code that @andypost mentioned.
We're looking for a way to do this trough the entity API; in pseudocode
if ($field instanceof OptionsProviderInterface) {
$allowed_values = $field-> getPossibleOptions ();
}
Apart from that, we'd need to fix the test + if possible add additional unit / kernel test coverage. However that extra testcoverage is very low priority.
Comment #41
borisson_options_allowed_values should be an easier way to do this, thanks @swentel
This patch also makes some other changes for reducing the complexity of the plugin
Comment #43
andypostI'd better use !empty() here and added interface check for field interface
Comment #44
borisson_Thanks for that suggestion @andypost, I did some additional refactoring of the code to make it somewhat easier to read.
No idea how to fix the tests - but manual testing confirms that it works.
Comment #45
borisson_Go testbot, go!
Comment #47
borisson_I think the integration test fail is related to #2809797: Create test for multiple facets on a page. - so I'll go there to figure that out.
Comment #48
borisson_So - just to keep everything updated in the issue queue and not just in my head:
- this patch needs to updated to fix the failing unit tests.
- the issue #47 links to should be the one where we fix the integration test so that this can be fixed.
Comment #49
borisson_Looks like #2809797: Create test for multiple facets on a page. is not the reason for the fails here. Diving back in.
Comment #50
borisson_The work I did on the plane.
Comment #52
borisson_Fixes unit tests.
Comment #54
borisson_Comment #55
sukanya.ramakrishnan CreditAttribution: sukanya.ramakrishnan at Workday, Inc. commentedThe List item processor doesnt work for fields that are on an entity reference field on a document. Before this patch , we could get the field settings using the datadefinition method like in this patch https://www.drupal.org/files/issues/facets-Fix_TranslateEntityProcessor-... , but i wonder why we take a longer route like in this patch?
Thanks,
Sukanya
Comment #56
borisson_@sukanya.ramakrishnan: I don't think we were explicitly supporting that use-case. I don't mind adding it back in though if it's not hard to do. In any case, adding/supporting that usecase means that we'd need a test for that as well. I think we should probably do that in a seperate issue? Not sure. Maybe we can do that here as well.
Anyway, the datadefinition that we get from search api is not sufficient to get the information needed here.
Comment #57
sukanya.ramakrishnan CreditAttribution: sukanya.ramakrishnan at Workday, Inc. commentedOk will create a new issue for this usecase so that this issue doesnt get blocked. Thanks!
regards,
Sukanya
Comment #61
borisson_Committed, thanks!
Comment #63
borisson_Reverted, tests were failing because of this.
Comment #64
andypostWhy not allow ER field type?
And limit for "type" field name?
before using bundles you need to make sure that entity type support bundles
Comment #65
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedI am not sure why test would fail with this, I was having trouble running any tests with or without the patch. The tests would simply timeout locally and fail around the second test. Either way, for #64 I think @andypost is right I dont think there is a reason (that I have found at least that) ER field types have to be excluded. As for the second part I think
$list_bundles = $this->entityTypeBundleInfo->getBundleInfo($entity)
returns an empty array if the$entity
doesn't support bundles so maybe just an!empty
check would be enough. I have manually tested the committed/reverted patch and it works great for what I originally was solving. Thoughts about what still needs to be done here?Comment #66
borisson_I can't remember why I did this. I'll update if I remember.
Comment #67
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedSo I spent some time getting this working for a couple more scenarios, both for list fields created in code using
basefieldDefinition::create
and for an ER field. There are a couple of things that I had questions on and wasn't 100% sure if they were correct: The facet was checking if the source was an instance ofSearchApiFacetSourceInterface
did that need to be aSearchApiDisplay
now? Also I was hoping someone with a better knowledge of ER fields and the search API could comment. I think having to digg down through the field definitions is a bit commbersome. Maybe a new processor is needed there but I figured I could start with it here and someone could give some context.Thanks,
Nick
Comment #68
ndrake86 CreditAttribution: ndrake86 at Workday, Inc. commentedI actually ran into an instance where I broke my own patch. There was a search API field being added by a processor and there is no of course no fieldDefinition for that so this patch should fix that. Interdiff still with #54
Comment #69
borisson_I think we can commit this, looks good. Going to give the testbot some time to look at this first - I made some small changes for readability.
Comment #70
borisson_Changing author.
Comment #72
borisson_Committed and pushed, thanks for sticking with this.