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.
Hi,
I set an argument passed to the view inside a panel as a string (because it's multi-word).
I also need to use that argument in the page title but with first letters of words uppercased.
So, I modified the file ctools/plugins/contexts/string.inc to make this string substitution available.
$plugin = array(
'title' => t('String'),
'description' => t('A context that is just a string.'),
'context' => 'ctools_context_create_string',
'keyword' => 'string',
'no ui' => TRUE,
'context name' => 'string',
'convert list' => array(
'raw' => t('Raw string'),
'html_safe' => t('HTML-safe string'),
'uppercase_words_HTML_safe' => t('HTML-safe string, first letters uppercased'),
),
'convert' => 'ctools_context_string_convert',
'placeholder form' => array(
'#type' => 'textfield',
'#description' => t('Enter the string for this context.'),
),
);
function ctools_context_string_convert($context, $type) {
switch ($type) {
case 'raw':
return $context->data;
case 'html_safe':
return check_plain($context->data);
case 'html_safe':
return ucwords(str_replace("-", " ", check_plain($context->data)));
}
}
This works, but I like to avoid hacking core files whenever possible.
Is there a way (hook or something) to put this transformation in a custom module where all of my other customizations reside, thus avoiding hacking core ctools files?
Thank you.
Comment | File | Size | Author |
---|---|---|---|
#3 | ctools-uppercase-string-context-substitution-1163168-3.patch | 764 bytes | kobee |
Comments
Comment #1
Max_Headroom CreditAttribution: Max_Headroom commentedThanks for this.
I guess like you, I have been searching for a solution to do this without having to hack ctools.
Just an error in your code:
should be
Please if somebody have a solution without hacking ctools. Let us know. Maybe we will learn something :)
Comment #2
merlinofchaos CreditAttribution: merlinofchaos commentedWhy don't you submit a patch instead? This seems useful.
Comment #3
kobee CreditAttribution: kobee commentedIndeed this is very useful for SEO.
Here I made a patch for 7.x
Comment #4
Max_Headroom CreditAttribution: Max_Headroom commentedTested.
I guess it does not need many tests for such a small patch.
Comment #5
kobee CreditAttribution: kobee commentedYes, tested on production too.
Can you commit please?
Comment #6
Max_Headroom CreditAttribution: Max_Headroom commentedPlease can we have this committed?
Comment #7
japerrySounds good. Committed.