Closed (fixed)
Project:
Context
Version:
7.x-3.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
7 Sep 2010 at 14:58 UTC
Updated:
3 Apr 2017 at 12:44 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
ar-jan commentedIt seems Persistent URL will do this for you.
Comment #3
ar-jan commentedHm, it seems I was wrong. When I read that Persistent URL was started as context_prefix, I assumed it was something that played together with Context module and it would therefore work with query strings. But you could have query strings without using PURL, and now that I'm experimenting with this, I can see that defining a condition with Path "*?query=string" does indeed not trigger the condition.
Is there a way to make Context work with query strings? Or would that be a feature request. Thanks!
Comment #4
doublejosh commentedSounds like a feature request... and I want it too!
Comment #5
tribe_of_dan commentedMe too!
Comment #6
ar-jan commentedChanging status.
Comment #7
kristen pol+1... actually need this right now... am trying to figure out a workaround.
Kristen
Comment #8
kristen polI have created a patch that extends the path condition plugin to create a query string condition plugin that works in the same way as the path plugin. The patch is against version 6.x-3.0. Please see attached.
It seemed cleaner to me to make a new plugin but, if you prefer that the path condition plugin be changed to work with query strings instead, please let me know and I can see if I can to do that.
The nice thing about having it be it's own plugin is that it could be used with the path plugin as well, e.g.
paths:
some/*
*/another
query strings:
destination=foobar
destination=somewhere*
I have only tested this for a simple case so it would be great if others could apply the patch to their context module and try it out (clear your drupal cache after applying the patch).
Kristen
Comment #9
kristen polargh... here's the patch
(Updating attribution on November 23, 2015.)
Comment #10
kristen polComment #11
Offlein commentedHi, I tried that. Specifically I wanted the context to be set for only the first page of a paginated query.
So, I tried:
That way it would still work on the first page. Seems to not work, however! I'm setting this in the "query string" condition (which is, I believe, the right place).
Comment #12
NaX commentedI also could not get the code in the patch to run, so after some digging I added the following to context_init() after the "path" context. Now the code at leasts runs, but I cant get it to work as expected.
Comment #13
NaX commentedOk, I found that the match function inherited from path was just not working for me. So changed context_condition_query_string.inc to use a custom query string matching function and it now seems to work. Its maybe not the most elegant why of doing it but I am not good at regular expressions and I did this in a bit of a hurry.
I hope it helps.
Comment #14
doublejosh commentedSo excited to see this. My use case to let editors create multiple layouts of a page (or block inclusions) that can be arranged dynamically!!!
Comment #15
fxarte commentedHas anyone tested this?
Comment #16
fxarte commentedThis needs work not only the the match function but elsewhere in the code because the variable $subject does only include the $_GET['q'] value
Comment #17
mrfelton commentedPatch in worked fine for me. Thanks.
Comment #18
mrfelton commentedI'm not sure what the other problems postes were with the original soution, but it's working well for me - aokhough the patch in #9 doesn't work without the modification mentioned in #12.
Attached patch combines those two changes into a patch that can be applied with Drush make.
Comment #19
betty66 commentedAfter apply patch #18
My url: www.mysite.com/restaurants/wogaboo?title=a&zone=2&type=24&kids=31&offer=33
Conditions:
path: restaurants/*
query-string: title=a
Reaction:
theme->Section class: myclass
Don't work, "myclass" not show in body tag
any help?
thanks
Comment #20
dmenefee commentedI found that if I include the match() function in #13 in the patch at #18, it works like a charm.
Comment #21
kalis1Here is another version of the patch provided in #18 (same code, just a more classical format).
This patch works very well for me (on 7.x-3.0-beta2).
@dmenefee : could you provide more info on what was wrong with the match() function inherited from the context_condition_path class ?
Thanks
Comment #22
kalis1Changing the version of the feature request...
Comment #23
rsaddington commentedGreat patch, tested with 7.x-3.x-dev 2012-Jun-30 and works perfectly.
Would be really keen to see this in the next official release.
Comment #24
Offlein commentedI've been using this (#13) now actually for almost a year and it's been working fine. I'd really like to see it implemented.
Two things to note -- there's some [potentially] undefined variable issues going on in /plugins/context_condition_query_string.inc. One, in
$_SERVER["QUERY_STRING"] is not always defined (and throws a PHP Notice when I run Cron).
Later, in this function of class context_condition_query_string...
I get an undefined offset PHP notice - I guess because $pair may not actually be an array. If those are (or were) fixed, I'd call this bad boy "ready to go". Both are minor issues.
Comment #25
zabelc commentedThis works very well for me against 7.x-3.0-beta4. I did have to patch with -p1 though.
Comment #26
alanom commentedIs there a good reason why this work from well over a year ago hasn't been tidied up and committed? Maybe it's just my setup but the patch(es) seem to have gone stale against -dev.
Here's a patch that:
$_SERVER["QUERY_STRING"]exists before trying to use it?one=1&two&three=3) into the same array structure as the others, usingtrueas the valueBased on the latest -dev release. If you don't see the 'Query string' option in the Context UI dropdown after applying, I found I had to disable then enable the module before it appeared (clearing caches didn't help).
Comment #27
mrfelton commentedPatch from ##26 updated to apply cleanly against latest code
Comment #28
mrfelton commentedLast patch seemed to be missing the new file that provides the plugin.
Comment #29
tsi commentedLast patch works great with 7.x-3.0-beta4.
@alanomaly - no need to disable-enable context, running update.php did the trick for me.
Comment #30
tribe_of_dan commentedIs it possible to backport this to d6? I have a site that would love to have this.
Comment #31
weseze commented#28 works great here. I did have the clear cache 2 times before the plugin showed up in context.
Comment #32
nightlife2008 commentedIs this going to be added to any release any time soon?
I got some remarks from a client that I should move this patch into a separate module with context hooks, but if this is going to be in the upcoming release, it's an obsolete remark.
Thanks in advance!
Comment #33
colin_young commentedI vote for including this in the core context. It seems like a general enough requirement and is very similar to the existing path context.
I am trying to implement this in the meantime in my custom feature-based module, but I can't get the new context to appear. Both hooks (hook_context_plugins and hook_context_registry) seem to run (at least watchdog adds events to the log if I log events within those hooks). I'm going to keep an eye on this thread, but in the meantime I'm going to enhance my PHP condition to satisfy my requirements for query string matches.
Comment #34
kalis1Just a note to confirm that patch in #28 works well with 7.x-3.0-beta6.
Comment #35
brunorios1 commentedit is working on my localhost but it isn't in production.
any help?
Comment #36
NaX commented@brunorios1
Is there a difference in PHP versions maybe and have you flushed the cache
Comment #37
brunorios1 commented@Nax,
i was using .htaccess rules to redirect the users to a folder with the drupal site, like this:
so i moved the site to the root and it works!
thanks!
Comment #38
lpeabody commentedFigured I would add my vote to move this into core Context.
Comment #39
dealancer commentedThe patch #28 does not add new context condition for me :-/ 7.x-3.0-beta6 is used.
Comment #40
NaX commented@dealancer
Try flushing your Drupal cache or some have suggested that you need to run update.php.
Comment #41
kristen polRTBC++ #28 works great! This is very useful and works great with Meta Tags (you can specify meta tags for pager pages like foobar?page=1) using the metatag_context module. Please commit :)
[update] For those not seeing it, clear your cache multiple times.
Comment #42
dddbbb commentedRBTC +1
Have used the patch in #28 against Context 7.x-3.0-beta6 and it works great (flushed cache several times as recommended).
Comment #43
iamEAP commentedFor those who need this functionality and are not able or willing to patch Context, I broke this off into a module with a little bit more flexibility (and unit tests):
https://drupal.org/project/context_query_param
Comment #44
kristen polThanks @iamEAP! That sounds awesome :) Since this issue is 3 years old and the patch is 9 months old, it doesn't look like this is getting into Context any time soon :/
Comment #45
f0ns commentedWhen I install this module (https://drupal.org/project/context_query_param) with Context 7.x-3.0-beta7 the Context Module stops working, no errors are given. The patch on #28 works with Context 7.x-3.0-beta7!
Comment #46
iamEAP commented@f0ns, could you file a bug report in the Context Query Parameters issue queue?
Comment #46.0
iamEAP commentedfix typos
Comment #47
colanCommitted in cf46694.
Comment #48
leex commentedGreat to see this committed.
For those having trouble I had to format like this when targetting a specific value equals:
*shs_term_node_tid_depth=30*
Comment #50
tmcfarlin4 commented#48 Thank you. The context was being recognized on my local without the asterisks, but migrating to server resulted in it not! The asterisks were necessary.. have yet to identify why this worked in one environment.
Comment #51
steveOR commentedYes #48 thank you, I was lucky to find this thread right away. You may not need the asterisks around the query string value when working locally, but when you try your contexts on Pantheon or Acquia for instance then they ain't gonna work without the enclosing asterisks!
Comment #52
Katy Jockelson commentedThank you everyone, particularly iamEAP for the module :)