balintk created a sandbox with two plugins for query strings: a context to handle specific query string arguments, and a relationship to load an entity from the query string. I figured these were useful enough that they should be submitted as a patch to CTools itself rather than live on in an obscure sandbox.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DamienMcKenna’s picture

Status: Active » Needs review
FileSize
5.17 KB

I renamed the original query_string plugin to more closely match the existing CTools standard, but otherwise this is all balintk's code.

DamienMcKenna’s picture

Note: I haven't tested the code, am just helping the process along.

milos.kroulik’s picture

It seems to work properly in my case (loading node by its nid from query string and using it to modify breadcrumbs).

Michelle’s picture

Status: Needs review » Needs work

I added the context and that went fine. Not knowing what to put for the "fallback" I just wrote "fallback". Then I looked to see how to make it show up somehow and realized that there was a relationship so I added the relationship to node. At that point, I realized that my "fallback" made no sense so I went back and changed it to a "2" thinking that it would fallback to NID 2 if there wasn't an NID in the query string. As soon as I saved it, I got a WSOD. Looking in the logs, there is this error:

[Mon Dec 22 17:32:28.290690 2014] [:error] [pid 23970] [client 127.0.0.1:55042] PHP 17. ctools_entity_from_query_string_context($context = *uninitialized*, $conf = *uninitialized*, *uninitialized*) /var/www/html/drupal-contrib/sites/all/modules/ctools/includes/context.inc:930, referer: http://michelle.dev/drupal-contrib/admin/structure/pages

I'm not sure what that means or how to fix it but considering I can't get to that page at all, now, due to the WSOD, something at the very least needs some error checking. :)

fubhy’s picture

Status: Needs work » Needs review
FileSize
6.6 KB

Let's add an access plugin while we are at it.

Albert Volkman’s picture

For the access plugin, would it not be better to check for a querystring's value versus just its mere existence?

fubhy’s picture

Both is useful I guess. So a second access plugin that checks the value could be good.

Albert Volkman’s picture

I'm relatively noobish at ctools plugins. When I tried to grab the $context within the access callback, I always get null. Am I missing something?

Andrew_Mallis’s picture

Using the query string to trigger pane visibility and works well.

Andrew_Mallis’s picture

FileSize
15.28 KB

so a query string is key-value pair like

?[key]=[value]

but the form is asking us for a key on the pane configuration
string key label is wrong

I am inclined to want to put a value in here.

Lemme consider this UX some more. It's unclear.

NWOM’s picture

#6 worked amazingly. Thank you so much.

maxplus’s picture

Thanks,

#6 also works great for me. Using it's access plugin functionality.

SaytO’s picture

#6 it works, thank you very much

Can make 2 variant and give context to access a URL parameter!

geek-merlin’s picture

Status: Needs review » Reviewed & tested by the community

So we have some confirmations. Code looks totally straightforward.

mortona2k’s picture

Worked well for me!

japerry’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/plugins/contexts/query_string.inc
@@ -0,0 +1,89 @@
+      $context->data = $_GET[$data['key']];

Need a check_plain here?

geek-merlin’s picture

> Need a check_plain here?

Sanitization is done on output, so imho no.
https://www.drupal.org/node/28984

NWOM’s picture

Status: Needs review » Reviewed & tested by the community

Setting this back to RTBC then.

Albert Volkman’s picture

LGTM

rivimey’s picture

The patch (of course, given it's just new files applies cleanly to current 7.x-1.x.

I did a simple visual check of the code and think some example use-cases would be helpful in the @file comment block and/or in the plugin description string, as I had to look hard to 'get' what was meant. I was tripped up by what 'query string' meant.. my head was full of SQL. I guess I'm in agreement with #11

However, that doesn't change whether the code works, and at least there are comments :-)

I think overall looks good to go... can always improve later.

rivimey’s picture

  • japerry committed 759d366 on 7.x-1.x authored by fubhy
    Issue #2208433 by DamienMcKenna, fubhy, Andrew_Mallis: Query string...
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Okay otherwise this works fine, and doesn't change anything else so thats good. Committed!

Status: Fixed » Closed (fixed)

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

Jorrit’s picture

The contributors to this issue may be interested in a feature request with patch that I just posted:

#3032363: Allow setting NULL as fallback value in query string context