Closed (fixed)
Project:
Facets
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
17 Mar 2017 at 15:31 UTC
Updated:
30 Oct 2017 at 23:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
borisson_If we can, we should do this. I think it's probably a new method on the facet source plugin's. That'd be a good thing to do. We should load and execute the view but move it to a method on that plugin. That'd be the easiest way to implement this correctly I think. Going to float this by Nick and Jimmy to see if they agree with that approach.
Comment #3
dragos-dumi commentedI attach a patched with a suggestion on how we could start this.
Extend the url processor with getFilterString method to get the value string of the facet
and this to add/remove specific query values for a raw facet value.
and than we could add a face source method to use these 2 methods
Comment #4
borisson_Doing this will break the API, so we should do this before we tag the first beta.
Comment #5
borisson_Mainly docs changes. Going to ask @StryKaizer for a review, as he will be able to look at this from the pretty paths perspective as well.
Comment #6
strykaizerpublic => protected
Can we return an url object instead if possible?
Facets pretty paths does not use GET params, thus will only be able to generate URL objects.
We can rename this function to getFacetItemUrl if so.
I think this is not required for the interface.
Comment #7
strykaizerComment #8
borisson_Fixes most of the remarks of #6.
Comment #9
edurenye commentedIn that issue was added a @todo pointing to this issue.
Comment #10
dcam commentedFor the record, this is exactly what ERFL does too for its formatters.
Comment #11
strykaizerHere is an example on how to generate a facet link in code.
When all you need is linking an entity reference field to the facet search, I suggest using the ERFL module as mentioned above which does basicly the above code, and provides field formatters for your entity references.
The code from #8 does not really adress this issue, not sure if we need this refactor.
Comment #12
strykaizerComment #13
dcam commentedFor those who don't know yet, ERFL Beta 3 comes with a second formatter that outputs a raw URL and nothing else. It's intended to be used with Views to enable you to rewrite any field as a link to a facet, not just the entity reference field it comes from.
Comment #14
dragos-dumi commentedThe example in #11 is a valid one, except that if you have the facets already processed, will give you the first version of url, which may contain other filters (I was working on improving facets_system_breadcrumb_alter)
Comment #15
edurenye commentedI think at least we have to remove the @todo from here #2717537: Breadcrumbs support also I think we can improve the code there, and I don't think adding ERFL as a dependency is a good idea, but not really sure.
What do you think?
Comment #16
strykaizerWell, this makes sense. If more people need this functionality, the code above is not that clean to re-use.
Lets create an utility service for this.
Comment #17
strykaizerAttached is an utility service to simplify this process.
You can generate an Url object for a facet link using following code, where 'tags' is the facet id, and 35 is the raw value (term id in this case)
Comment #18
strykaizerComment #19
dragos-dumi commentedok, thanks. i will open a new issue for improving the code from #2717537 based on this
Comment #20
borisson_I don't know how to write the test - this is the current dump of what I have.
Comment #21
strykaizer@dragos-dumi noticed that this helper function returns the active facets too
Lets fix/test this
Comment #22
borisson_Test! Green test! Woo.
Comment #23
borisson_Back to needs work per #21
Comment #24
dcam commentedI hadn't patched ERFL yet, but I realized about a week ago that this has some code smell. Core typically uses
reset()in these situations, which seems like the safer thing to do instead of risking an undefined index warning. There doesn't seem to be any guarantee that a UrlProcessor won't remove Results and then return an empty array.I modified #22 to use
reset()and to do a basic check for a Result before returning.Comment #25
dcam commentedSorry, status.
Comment #26
dcam commentedBack to Needs Work again.
I think I would prefer to test instead of fix. If a person clicks an ERFL link within a result displayed on a search result page, I think they would expect it to narrow the results, not reset them to only be filtered by that facet. When I demoed ERFL to my DUG this was the behavior they expected and were pleased to see happen. Thoughts?
Comment #27
dcam commentedI tested this by temporarily updating ERFL's formatter plugin base to use the new service. It was working well. The functionality gets a +1 from me.
I thought about the patch some more after posting #26. Assuming you decide not to remove the already-active facets from the URL, does this really need a test? Adding the active facets is a function of the URL processor that is configured. So is there a point to testing it at the service level? The result will vary depending on what the processor does.
Comment #28
dcam commentedI did a few more things:
1. Removed unused classes from the test.
2. Fixed an "Only variables should be passed by reference" error that was a result of the change to
reset()in #24.3. Added an InvalidArgumentException if an invalid facet ID is passed to createUrl().
4. Added a test for the exception.
By the way, from the perspective of someone who is consuming this API, I don't mind passing a Facet object instead of a facet ID. In that case, most of what I added in this patch would be irrelevant. I don't know if there was a reason for requiring the ID as a parameter instead. Of course, ERFL already has to load Facet objects to do its thing, so I may be biased because it's not a big deal for me.
Comment #29
borisson_We should keep it as an option I think, I would prefer the current implementation being in
::createUrlWithCurrentFiltersand a new one in::createUrl.The result will vary on what the processor does indeed. But since this will be an entrypoint used by a lot of custom code we want to be 100% sure how it works with the current implementation of the query string url processor. Breaking that one isn't really an option at this point.
I know the additional load can seem like overkill but this keeps the api simplest for other usecases, I think. I'll discuss this later today.
I also made some changes to the code, I like the Exception but they should never use additional API calls, changed that out. Move the test to the correct namespace as well.
Comment #30
borisson_NW per #29.
Comment #31
borisson_In theory this should work.
Comment #32
borisson_Now with the patch.
Comment #33
dcam commentedMakes sense.
Sorry I forgot that docblock.
Comment #34
dcam commentedHow about this? I eliminated some code repetition.
Comment #35
borisson_@StryKaizer had the same idea earlier - thanks @dcam! I haven't written a test or manually tested this so not sure if it will work.
Comment #36
dcam commentedYeah, I took a shot at writing a test, but I couldn't figure out how to set an active facet since the ID is passed and the facet object is reloaded from storage. I figured someone more familiar with writing tests for the module might know.
Comment #37
borisson_I now added a test to test all this behaviour, but it looks like it's not working properly.
Comment #38
borisson_The problem was here *points to self*. I uploaded the wrong patch. New patch incoming!
Comment #39
borisson_Looks like the testbot is not picking up on the new testfile, it should be red - not green. Now to figure out why that is.
Comment #40
borisson_I think the namespace was incorrect, hoping for testfails now.
Comment #41
dragos-dumi commentedComment #43
dragos-dumi commentedComment #44
dragos-dumi commentedOn #2908937: Dependend Facets don't reset after Conditions are not met anymore. we need to overwrite the facet url so that removes another facet filter key from url. Could this be possible also with an url processor method?
Another situation this kind of method would be helpful is in facets_summary reset link processor, which now removes the query parameters, but that would not work for pretty facets url processor
Comment #45
strykaizerWorking on this
Comment #46
strykaizerBeta blocker again, changed the URL processor interface to allow building links with multiple items, as required by e.g. breadcrumbs.
The syntax for the helper service changed a bit to allow users to generate links with multiple facets being active.
Tests will probably fail, needs to be fixed.
Pretty paths will need to be fixed too (but I got a working version on my local machine).
Example code
The getUrl method accepts an extra boolean to disable currently active filters, when using this method in a request which already has active filters.
Comment #48
strykaizerShould work now, but tests still WIP
Changing category to Task as we really need this in for many reasons (the part which allows you to generate an url for a specific combination that is)
Comment #50
borisson_Still 2 remaining fails locally - but I don't know why.
Comment #52
borisson_Fixed the unit test + cs fixes all around.
Comment #53
strykaizerStill working on this, buildUrls needs to use machinename=>url_alias conversion too
Comment #54
strykaizerWe should still write a test which checks if a facet with a different url_alias then the facet id generates a correct url.
This was still failing now (diff attached fixes this).
Comment #56
borisson_Tests should be green again now.
Comment #57
borisson_Rebased to get it back to work, should we commit this as-is @StryKaizer??
Comment #59
strykaizerFine for me
Comment #61
borisson_Ok, thanks!
Committed and pushed. This was the last of our beta blockers, I'd suggest that we go trough the entire queue again to see if any of the open issues are still blockers - if they are not we can tag the first beta release.
Comment #62
dcam commentedCongrats on clearing out your beta blocker queue!