Download & Extend

Panels Keyword substitutions don't work for "Input on pane config" argument on view panes

Project:Chaos tool suite (ctools)
Version:6.x-1.x-dev
Component:Views Content
Category:bug report
Priority:major
Assigned:Unassigned
Status:needs review

Issue Summary

Views 7x-3x (10-7)
Panels 7x-3x (10-7)
I'm figuring this is a Panels issue because if you enter the actual text the view pane resolves fine.
Usecase when viewing an Article of a particular type e.g. FAQ via a Panel Page I would like present a view pane of similar type of articles.

Context keyword %node:field-article-type returns FAQ in a custom content region on the page.
In Views I set the argument input for the contextual filter to "Input on pane config".
In Panels I add the view pane as content and enter %node:field-article-type (and I tried %node:field_article_type) as the keyword substitution - returns nothing
In Panels I edit the settings for the view pane to FAQ and - it returns a view with all the FAQ type articles

I'm assuming since it says "You may use keywords for substitutions." under the input that you can use keywords.

Comments

#1

Component:Panel pages» Views panes
Assigned to:Anonymous» tpopham

I'm having the same problem. I can hack around it for now by fixing the arguments, but that makes for annoying maintenance. Tracing through the code a while, I found $context empty in views_content_views_panes_content_type_render(). Reaching the unpack function from import/export, I finally noticed that every views_panes type from {panels_pane} has no context embedded in its configuration. I reason that the problem is with Views, but that bit is handled by CTools, so someone with some authority should probably punt this over there.

#2

Assigned to:tpopham» Anonymous

#3

Status:active» needs work

The 'required context' values passed to views_content_views_panes_content_type_render(...) are always empty for UI built input arguments. This traces back to ctools_views_get_argument_context(...) ctools_content_select_context() in ctools/includes/views.inc. UI built input arguments seem to always have type `user', but ctools_views_get_argument_context() only works on those of type `context'. I'd submit a patch, but I don't know if type~context is a useful case. Does anyone with some history know if `context' should get replaced with `user' or if another branch is in order? The function filters out panel contexts that don't map to pane contexts, and no other facility exists for propagating other contexts for use as keywords.

#4

Status:needs work» active

#5

I got it narrowed to an insufficiently robust ctools_content_select_context() filter. The function doesn't anticipate arguments, and so in the absence of context configuration data, the render method doesn't get any data to substitute for the keywords. I'm just going to branch the logic inside the function to handle the possible alternative. Maybe the configuration should be augmented with a `context' keyed array mirroring the `argument' (sic?) keyed array earlier in the pipeline, though?

#6

The select context filter is specific to context arguments, so it should be left as is. The views_content_views_panes_content_type_render() function expects context arguments parallel to the data returned from display_handler->get_argument_input() (see that weird little array_shift()). One could leave the context arguments at the array head and append any other contexts as a tail. Under the current implementation, no other contexts reach the render stage.

I'm not going to submit a patch that hacks an API to include extraneous data. I think a hook for appending additional contexts should be added to the API. Such an implementation would leave existing API implementors unbroken and facilitate the sought workflow.

For now, I'm just going to use context arguments, as they look very functional. If someone were desperate to vaciliate between hardcoded values and keywork dispatched values, then they could attach context arguments in parallel with ordinary arguments, with the context arguments flagged optional. Ironically, this usage would trick the system into including the necessary context for the ordinary arguments, probably making the keywords work.

#7

Just got to thinking, the text/keyword argument facility looks older than the context argument facility. As such, I imagine that the older logic from text/keyword has broken somewhere as the system shifted to incorporate context arguments. Rather than shifting the system yet again to handle text/keyword (probably breaking both facilities), I'm going to explore piggybacking the text/keyword functionality on top of the context system. Under my current understanding, this could happen as follows:

  1. The UI remains as is.
  2. The ctools_content_select_context() function works on both context and argument keyed values of the $conf array to build the contexts fed to the renderer (you can't hardcode context arguments under pane settings, making them less powerful than text/keyword arguments--if you could, I would happily forget about text/keyword arguments).
  3. The renderer completely ignores the argument keyed values of the $conf array, and the render's `context' and `user' cases unify to a single case.

My biggest reservation is the handler's get_argument_input() behavior. I looked in there a long time ago, and abandoned understanding it because it looked complicated and seemed to behave properly. It has to provide arguments in the ordering expected by Views, so I don't want to touch it (any fix should respect the boundary between Views and Panels, so why not move that boundary a little further to include get_argument_input(), yeah?).

Combining the two cases, that array_shift() ugliness can be removed from the renderer. If the refactoring materializes cleanly, then maybe the implementation could even be migrated to the handlers corner of the API to provide the text/keyword functionality for free to any context argument implementors. With the boundary between text/keyword and context arguments blurred, the UI for context arguments could be generalized to accept hardcoded arguments.

#8

Status:active» needs review

Well that was a bust. Context and selector are pretty tightly integrated. The system expects all kinds of extra stuff, and the payoff is too small. I created a new function to extract contexts based on keywords, and I modified ctools_content_select_context() to incorporate the resultant contexts. I overcame my reservation over altering ctools_content_select_context() because of the `content' qualifier. The returned context isn't particular to context arguments. Its docblock says, "Select the context to be used for a piece of content, based upon config." Case closed.

Oh yeah. I got it! Thanks for all of the input everyone!

AttachmentSizeStatusTest resultOperations
ctools-pane_config_keywords_lookup-1303024-08.patch2.65 KBIdlePASSED: [[SimpleTest]]: [MySQL] 0 pass(es).View details | Re-test

#9

I experimented with returning arrays only, like the fn's docblock claims, but it breaks anything that is keyword agnostic. This setup breaks my minipanels when my arguments are all keywords (an array_shift is called for a nonarray). I thought this was a flaw in the patch for a while, but I can't find a call from minipanels to the altered code. I have to dig further, but this may be a bug in minipanels. The call to ctool_context_match_required_contexts() crashes when minipanels passes its single context not mapped in an array. I really want a workflow with keyword arguments to minipanel constituents, so I'll be working the kinks out of minipanels also (step one is rolling back and excercising minipanels under the current dev release).

#10

Priority:critical» minor
Status:needs review» needs work

I've just been reading the front page of the Panels project, and I realized that the extra bit of generality that I thought keywords provide doesn't exist. Instead of, for instance, hardcoding a NID argument in a pane configuration, I can add an additional context to the pane owner, fixed to a particular node if I'd like, and then add a relationship to its author and then provide that context as an argument to the pane. Maybe the claim of keyword support ought to be removed instead, with an added upgrade path:

  1. Add a relationship to the pane owner for that last indirection from the keyword.
  2. Switch the pane's argument input to handle context arguments.

#11

Sorry to the OP, also. I just realized that my previous post doesn't bring much closure to the issue itself. Rather than text in a field to denote an article type, you should probably have a taxonomy term attached (and if there's only one FAQ, then you should attach it as a context to the pane's owner and then pass it to Views as a context argument). Under such a schema, I'm pretty confident that the context system would serve your purposes. I'm torn between normal and minor priority, but the context system is so elegant compared to the keywords, I feel that our usage pattern is more of a hack. If someone had a magic wand (*ahem*), I imagine that the entire keyword system would get junked and replaced with tokens, with keyword use relegated to content areas only. For instance, you could have a contextual filter that keeps only nodes with a field that contained some chunk of text. Sorry about that, I couldn't help myself. Seriously, you should be using a taxonomy. I could maybe see filtering on a phrase as a member of a body field useful beyond what's provided by context arguments, but I'm probably being unimaginitive.

P.S. If I already had 102 pieces of content with the text field, then I'd take a closer look at the Views Bulk Operations module (on a dev site first--never trust an infojunkie).

#12

Thanks for the response. As you mentioned I just converted article_type to a taxonomy term and used the contextual filter. I can't imagine how many hours have/will be wasted trying to get this to work. I agree that "You may use keywords for substitutions." should be removed. Hopefully this helps other avoid the pain.

#13

Project:Panels» Chaos tool suite (ctools)
Version:7.x-3.x-dev» 7.x-1.x-dev
Component:Views panes» Code
Priority:minor» normal
Status:needs work» needs review

I can confirm that I have had this problem, but I'm also fairly certain that this has actually worked, though I don't remember exactly when I used it, so it shouldn't be that complicated. The initial patch for this support was only posted this summer.

I'm setting needs review as I hope someone will review the patch and give some hints for what needs to be done. Also moving to Ctools, as that's where I believe it belongs.

#14

Note that the keyword system, these days, is mostly a layer over token.module anyway.

#15

I found this issue yesterday while building a taxonomy term driven page and the one line fix is fairly simple, I'll post it tomorrow.

#16

Component:Code» Views Content

The reported behavior happened when a replacement keyword was inserted into a views argument input field in panels. At render time, as there was no required context set in the views display plugin, and as such, entirely optional, ctools_content_select_context() would simply return NULL for a context (see line 756 of ctools/includes/content.inc) preventing the use of contextual keywords. The following fix solves the issue by setting the view_pane key to 'all contexts' as true, thereby forcing ctools_content_select_context() to process and return all the defined contexts. As far as I know this is a sensible approach since a view pane, much like a custom pane, can accept optional (contextual) arguments.

AttachmentSizeStatusTest resultOperations
ctools-views_panes_missing_contexts_1303024_16.diff1.57 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch ctools-views_panes_missing_contexts_1303024_16.diff. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#17

The solution from #16 works for me.

+1 on the patch.

#18

Status:needs review» fixed

Thanks devuo!

Committed and pushed. (Though your patches need to be made with -p1 which is the git default.)

#19

Status:fixed» needs review

Just figured out, that the change above, breaks some of my views panes.
Reason is that if all contexts is set, the order of the contexts isn't maintained.
Unfortunately views_content_views_panes_content_type_render relies on the order of the given contexts (see line 152).
The attached patch adds a check to the handling of all contexts to see if a specific order is needed and if so it calls ctools_context_select().
Unfortunately I had to adjust ctools_context_select() as well, to make it possible, to merge the ordered and the possible leftover unordered contexts.
ctools_context_select() now returns the array of contexts keyed by their name and not numerical anymore.
This modification could have unpredictable sideeffects - however in my tests everything seems to work as before.
Of course there are other ways to mix the ordered / unordered contexts - but this one was the most elegant I could think of.
Feedback welcome :)

AttachmentSizeStatusTest resultOperations
ctools-ctools-views_panes-missing-contexts-1303024-19.diff1.12 KBIdleFAILED: [[SimpleTest]]: [MySQL] Unable to apply patch ctools-ctools-views_panes-missing-contexts-1303024-19.diff. Unable to apply patch. See the log in the details link for more information.View details | Re-test

#20

I think you're right -- there woudl be side effects to that change to ctools_context_select because I'm pretty sure there's code that assumes the keys will be simple 0-index somewhere. I don't think we can change that.

I think instead view pane will probably need to correlate the required contexts from $conf['context'] to the all contexts block instead.

#21

How about this - I've just extracted the "ordering" code of ctools_context_select(), adjusted it a little bit and added it to the all contexts handling in ctools_content_select_context().

AttachmentSizeStatusTest resultOperations
ctools-ctools-views_panes-missing-contexts-1303024-21.diff857 bytesIdlePASSED: [[SimpleTest]]: [MySQL] 0 pass(es).View details | Re-test

#22

Status:needs review» reviewed & tested by the community

This patch resolves the issue - I tried to use $conf['context'] in the content plugin, and that also works, but I think this solution might be cleaner since it would apply for more plugins than just the views content plugin.

#23

@das-peter, do we still need to use the patch from #16?

#24

@dozymoe: The patch in #16 was committed already by merlin as of #18. Thus if you have a version prior to January 21, 2012 both patches are necessary, otherwise just #21

#25

Understood, sir!

#26

I seem to have similar issues in 6.x-1.8.

Is this a known issue in the 6 branch or does it make sense that if there is/was a problem in the 7 branch that there would also be a problem in the 6 branch? If so, is there a patch for 6.x-1.8 and/or could someone create one without too much trouble?

After countless hours/days of looking for a panels/views/relationships/arguments solution to fit my particular need, I think I finally stumbled upon the right solution with using a Panels keyword substitution when passing the panel argument to the view, but I run into problems that sound very similar to what is described in this issue queue. I feel like I'm a stone throw away from nirvana...

#27

The patch from #16 has caused the panel page that I use for OG to fail. The pane no longer returns either related OG nodes or OG members. If I revert this patch, then all works well.

Is there something besides clearing cache that I must reset or rebuild to make this work?

I had originally opened up issue 1428740 on OG when I updated to Drupal 7.12 along with updating all of my modules. It appeared that Ctools was not compatible with OG. That may not exactly be correct, but I'm not quite sure what to do.

[Edit] Answered my own question. I have applied the patch from #21 and it appears to have solved the problem.

#28

Thanks for the patch, #21. Worked like a charm.

#29

Any thoughts about porting a patch over to 6.x?

The folks over at #981416: Passing %keyword as Argument to Views Panes would likely be grateful (myself included). The issue is "closed (works as designed)", but the comments (#9) indicate that the issue was perhaps falsely labeled and closed.

For what it's worth, I tried applying the code in #16 and #21 to the corresponding files in 6.x.1.8, but they didn't seem to resolve the issue.

#30

Status:reviewed & tested by the community» needs work

+++ b/includes/content.incundefined
@@ -736,6 +736,16 @@ function ctools_content_select_context($plugin, $subtype, $conf, $contexts) {
+      foreach ($subtype_info['required context'] as $id => $r) {

I'd say change the one letter variable to something more expressive.

#31

My intention was to use the same code as it is used already on three other locations.
I'll happily refactor all of those, but please let us solve the issue first. I'm afraid creating a bigger patch will lead to something like "Why did you change all that working code and not just fixed the bug?" ;)

#32

As said from #29, It would be good to have a patch for D6.
Thanks.

#33

Status:needs work» reviewed & tested by the community

I agree with das-peter, let's leave the world changing things for later.

#34

I don't know that writing sub-optimal code because it was copy/pasted from other sub-optimal code is really a great idea, but can you open a follow-up issue to expand the one letter variables?

#35

Great! Patch in #21 worked for me.

I had upgraded OG, Panels, Pages, Views and ctools to current latest versions and the panels I'd set up to display OG view panes had stopped working as unable to get the OG context. Now works - phew!

#36

Would be nice if this patch could be committed. Forgot I had patched this and upgraded to the latest RC today and had to re-patch.

#37

Priority:normal» major

#38

Patch #21 works fine for me too.
I was trying to get OG groups working, as per the doc/tutorial, and node content didn't display in the panel; 'took a while to trace it up to this, however - the sooner it'll be comitted to RC, the better.

#39

Status:reviewed & tested by the community» fixed

I have a completely different fix for this that I committed a few days ago: http://drupalcode.org/project/ctools.git/commit/c5e94816acfe21057e1167a1...

#40

Is this a fix only in the 7.x-1.x world?

I tried the changes in views_panes.inc on 6.x-1.8 and am not seeing any change in behavior. That is, I continue to get results in my view when I input the contents of the field (e.g. nid from referenced field) in the pane config, but empty results when I try a keyword from context substitution.

#41

I'll have check 6.x -- I didn't think this bug had been backported to D6.

#42

Status:fixed» closed (fixed)

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

#43

Status:closed (fixed)» needs review

Just a quick reply to keep this open for merlinofchaos'scheck of D6. #32, #981416: Passing %keyword as Argument to Views Panes, and my own experience seem to indicate that the bug was backported to D6.

#44

Version:7.x-1.x-dev» 6.x-1.x-dev

Then let's move this to 6.x

One downside: I haven't done much of anything with 6.x in awhile, and I am having to pick and choose where I spend my time.