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.
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.
Comment | File | Size | Author |
---|---|---|---|
#6 | 2208433-6.patch | 6.6 KB | fubhy |
Comments
Comment #1
DamienMcKennaI renamed the original query_string plugin to more closely match the existing CTools standard, but otherwise this is all balintk's code.
Comment #2
DamienMcKennaNote: I haven't tested the code, am just helping the process along.
Comment #3
milos.kroulik CreditAttribution: milos.kroulik commentedIt seems to work properly in my case (loading node by its nid from query string and using it to modify breadcrumbs).
Comment #5
MichelleI 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. :)
Comment #6
fubhy CreditAttribution: fubhy commentedLet's add an access plugin while we are at it.
Comment #7
Albert Volkman CreditAttribution: Albert Volkman commentedFor the access plugin, would it not be better to check for a querystring's value versus just its mere existence?
Comment #8
fubhy CreditAttribution: fubhy commentedBoth is useful I guess. So a second access plugin that checks the value could be good.
Comment #9
Albert Volkman CreditAttribution: Albert Volkman commentedI'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?
Comment #10
Andrew_Mallis CreditAttribution: Andrew_Mallis at Kalamuna commentedUsing the query string to trigger pane visibility and works well.
Comment #11
Andrew_Mallis CreditAttribution: Andrew_Mallis at Kalamuna commentedso a query string is key-value pair like
?[key]=[value]
but the form is asking us for a key on the pane configuration
I am inclined to want to put a value in here.
Lemme consider this UX some more. It's unclear.
Comment #12
NWOM CreditAttribution: NWOM commented#6 worked amazingly. Thank you so much.
Comment #13
maxplus CreditAttribution: maxplus commentedThanks,
#6 also works great for me. Using it's access plugin functionality.
Comment #14
SaytO CreditAttribution: SaytO at Metadrop commented#6 it works, thank you very much
Can make 2 variant and give context to access a URL parameter!
Comment #15
geek-merlinSo we have some confirmations. Code looks totally straightforward.
Comment #16
mortona2k CreditAttribution: mortona2k commentedWorked well for me!
Comment #17
japerryNeed a check_plain here?
Comment #18
geek-merlin> Need a check_plain here?
Sanitization is done on output, so imho no.
https://www.drupal.org/node/28984
Comment #19
NWOM CreditAttribution: NWOM commentedSetting this back to RTBC then.
Comment #20
Albert Volkman CreditAttribution: Albert Volkman commentedLGTM
Comment #21
rivimeyThe 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.
Comment #22
rivimeyComment #24
japerryOkay otherwise this works fine, and doesn't change anything else so thats good. Committed!
Comment #26
Jorrit CreditAttribution: Jorrit at nCode for DOM Digital Online Media GmbH commentedThe 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