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.
It would be great if CTools would allow you to create a custom string context in the UI. The current implementation has a "no ui" value set, but why can't we allow that to be set? There are a number of neat use cases you might want to add a custom context.
Comment | File | Size | Author |
---|---|---|---|
#16 | allow_string_context_to-1774434-16.patch | 867 bytes | sylus |
#7 | ctools.code_.1774434-7.patch | 1.49 KB | Angry Dan |
Comments
Comment #1
populist CreditAttribution: populist commentedHere is a patch that changes the module!
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedHuh. I have no idea why string contexts were never allowed in the UI. Maybe just in the early evolution of the system they didn't seem at all useful.
Comment #3
populist CreditAttribution: populist commentedThe use case that I found this most helpful was when I wanted to restrict certain content types to certain panel pages. This was really helpful in the context of making "administration" Panels because each panel page could be given a string context (i.e. "panopoly_admin") and then each content type that corresponds to administration can require that context. This is cool because then the admin content types *only* show up on admin panel pages since they require said context.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedHmm. I'm not sure string contexts are really what you want, there. You can't require specific strings for the content to show up, only that a string context exists.
I think you actually want specific types of contexts that correlate exactly to specific types of contexts.
So a "panopoly admin" context which can then be added to pages to say "Hey this is a panopoly admin page" and the like. A built in page task could then provide the basic panopoly admin page with that context baked in pretty easily.
Comment #6
geek-merlinIt seems the committed patch allows defining a string context but the value can not be set there which makes this useless for site builders in panels ui.
This patch fixes it.
(Note: we might want to do the same for token.)
Comment #7
Angry Dan CreditAttribution: Angry Dan commented#6 thanks for this patch it solved a problem for me - I needed to be able to pass a string from a panel to a mini panel and then on to a view. The only way to do this is via a string context on the base panel because mini panels (unlike views) doesn't allow you to input contexts as strings.
There is a small bug introduced in the patch, if you add a string argument to your panel then you'll get all kinds of trouble because of the check on
$data['string']
where the bit of ctools that converts an argument into a context passes $data as a raw string.See attached patch for a fix which keeps things backwards compatible.
Comment #8
mohamadaliakbari CreditAttribution: mohamadaliakbari commentedThanks. This patch was useful when I tried to pass "all" string to views to bypass some arguments.
Comment #9
geek-merlinThe last patch applies cleanly and fixes the issue.
Reclassifying as bug.
Comment #10
das-peter CreditAttribution: das-peter commented+1 from me. Looks clean and works as expected - thanks :)
Comment #12
japerryLooks good to me as well! Committed.
Comment #13
geek-merlinI've already worked a while with this patch now and i think it needs an improvement, to use placeholder tokens.
We should provide that in a followup.
Comment #15
sylus CreditAttribution: sylus commentedThis commit has resulted in the following error once updating past CTools 1.4.
Notice: Undefined index: string in ctools_context_create_string() (line 50 of /xxx/profiles/openatrium/modules/contrib/ctools/plugins/contexts/string.inc).
It was reported over here at: #2424017: Malformed (and useless) string context causes errors with new versions of CTools
Comment #16
sylus CreditAttribution: sylus commentedI have taken das-peter's suggestion to fix this and attaching as a patch. Let me know if this should go into its own issue.
Comment #17
das-peter CreditAttribution: das-peter commented@sylus Thanks for the patch. May I ask you to check the panopoly code too? As implied in #2424017: Malformed (and useless) string context causes errors with new versions of CTools it looks like something is creating a string context in a what that doesn't make to much sense. So before we fix the error message we might want to ensure that the context is properly created and we don't hide an underlying issue.
Setting to needs review - but not RTBC as I basically suggested that code ;)
Comment #18
B-Prod CreditAttribution: B-Prod commented@das-peter: the reported bug related to Panopoly is not caused by the changes discussed here, but to a wrong string context defined in Panopoly Admin default pages. So this should be fixed in Panopoly and do not interfere with current issue.
Comment #20
geek-merlinlike stated in #17 and #18: we should not silently hide malformed data input.