First, some background:
#1669918: Allow Panels to properly use Facet API blocks
#1925046: Inconsistency in how views_content module creates executes/renders views as compared to core block module

It seems that a lot of the code currently embedded in SearchApiViewsFacetsBlockDisplay::execute() needs to be moved to SearchApiViewsFacetsBlockDisplay::render()

I've worked a bit on a patch which works fine when the block module is used to place the Views facet block, but doesn't yet work 100% when Panels is used to place the Views facet block. What it DOES accomplish, however, is it allows you to place a Views facet block using panels which correctly affects any regular Facet API blocks on that panel, so it's still useful even in this broken state. It seems the reason it's broken is that the render method isn't called early enough in the process for it to attach its facet query when called via certain pathways. I'll revisit this soon but wanted to post a patch to get the ball rolling.

Comments

azinck’s picture

Patch attached.

azinck’s picture

Here's a follow-up that makes use of the query() method to inject the query alterations early enough. This fixes the problem I described above. Feedback welcome.

azinck’s picture

Status: Active » Needs review
mnlund’s picture

Nice work azinck.

I can't get it to work. No facets are displayed using the patch from #2. Before at least the facets was shown below the view. Have do you embed the view in the Panel page? Context, View pane or block?

azinck’s picture

ramsalt: I'm happy to try to help. Can you explain exactly what you're trying to do, what result you expect, and what's happening instead?

mnlund’s picture

azinck: I'm trying to add facets in Panels panes above the actual views output.

azinck’s picture

ramsalt:

Truth be told, I haven't tested that use-case. I've been embedding the views facet blocks using Panels. But I don't use views facet blocks on pages that already have a solr view, I've only been testing them on pages that don't have any other solr view to create a solr query for that page to allow Facet API blocks to work properly.

I'll have to test your use-case.

In the meantime, I'd recommend that you use Facet API blocks on your page as they're better than the views facet blocks in almost every way.

queenvictoria’s picture

This patch worked nicely for me in the given situation. Using Views Facets block in a Panels layout. Thanks @azinck.

lwalley’s picture

Patch in #2 worked for me, applied to Search API 1.4. The patch allowed me to add content View > Facets Block display to Panel whereas before I was getting Undefined index: theme in views_plugin->theme_functions() notice.

I noticed however that more links from the View do not appear to be displayed whereas they were before, I'll keep poking around.

lwalley’s picture

Apologies for the dumb questions that are about to come but I'm trying to get my head around why more links and pagination from Views Facets Block display don't work as expected, and I'm curious as to why the options in use do not appear to be for the current View display? For example when setting $limit in query() why does it use $this->view->query->pager->options['items_per_page'] rather than e.g. $this->view->display_handler->options['items_per_page'] (or some other correct way to get the value from the current views display)?

Also, with regards to pagination it looks like 'items_per_page' could have a value even when 'use_pager' is false, so should there be a conditional to check 'use_pager' is true before setting the $limit?

In my case it appears that $this->view->query->pager is always null, so my Views Facets Block display settings for pagination don't appear to be used - i.e. if I exclude my Views Facets Block displays in "Display for searches" in the actual search index Facets I always seem to get 10 items returned because of the hard coded $limit value, instead of whatever pagination options I'm actually using in the views display.

Not sure if any of that makes sense, or how relevant it is here. For now I'm just letting the "Hard Limit" in the index Facets do their thing instead.

drunken monkey’s picture

I don't think this is the right issue to post these questions. Or are they in any way related to the patch or the problem?
In any case, the answer is that Views is insanely complex and poorly documented, and I just stole the code from whereever I could find it as long as it seemed to work and no-one complained. If you know that some things are done the wrong way, or could be done better, please provide a patch (in a new issue) fixing those. Any help getting to correct Views code is very much appreciated!

As for the original issue and patch: I can't say I really understand those changes. But if someone else tries and finds them useful, too, and they don't break anything – why not. Waiting for tests / reviews for now.
In any case, thanks for your work on this!

lwalley’s picture

Thanks for indulging my questions and providing some context for the Views integration code.

In answer to your question 'are they in any way related to the patch' the technical answer is no, as far as I can recall the issues I saw were with the original code not the patch.

If my interpretations were correct and the more links and pagination are not working as intended then I think the questions I raised in #10 might be relevant to anyone looking to fully integrate Search API Views Facet Blocks with Panels.

drunken monkey’s picture

Status: Needs review » Needs work

Also, has there been progress on the issues mentioned in #4/#6 and #9?
For me, everything still works fine, but I'm not using Context, Panels or the like on my test site. So, these issues would also stand in the way of getting this committed.
Setting to "needs work" because of those.

azinck’s picture

Rerolled this patch against latest dev.

fengyun’s picture

Status: Needs work » Needs review
drunken monkey’s picture

Has anyone else tested this and can confirm it works? fengyun, have you tested it?
For me, everything keeps working, so it's hard to tell whether this patch moves things in the right direction. It would be great, if someone who had this issue could test it.

Robin_K’s picture

I have tested the #14 with the latest versions and it also fixed my problem.

Before, Facet Blocks added in a panel weren't displaying at all (but they did work when added in a region), the patch fixed the problem.

Thanks!

drunken monkey’s picture

Issue summary: View changes
Status: Needs review » Fixed

Great, thanks for testing!
Committed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.