Closed (fixed)
Project:
TOC filter
Version:
7.x-1.0
Component:
Code
Priority:
Minor
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
15 May 2012 at 11:09 UTC
Updated:
15 Apr 2016 at 12:17 UTC
Jump to comment: Most recent
For my site, I prefer to use a small arrow graphic in place of the "Back to top" label.
I did this by changing line 193 from:
return '<div class="toc-filter-back-to-top' . $class . '"><a href="#top">' . $variables['label'] . '</a></div>';
to:
return '<div class="toc-filter-back-to-top' . $class . '"><a href="#top"><img src="/sites/all/modules/toc_filter/back-to-top.gif"></a></div>';
Also, to move the graphic down to the same position as the h3 subheading, I added "div.toc-filter-back-to-top a:link, div.toc-filter-back-to-top a:visited {padding-top: 1em;}" to my theme's CSS.
Just a suggestion: could you add this as an option?
A side note: my original motivation to do this is that I run a multilingual site, and I found difficulty trying to get the "Back to top" label to show up for translation, and decided to avoid the problem and use a graphic instead.
Thanks!
Comments
Comment #1
jrockowitz commentedOne immediate issue is that $variables['label'] needs to passed thru the t() function and translatable.
I intentionally did not include a 'back to top' graphic assuming it could easily be added via the theme using something like the below code.
BTW, The 'back to top' graphic could also be added using CSS.
Comment #2
shadlaws commentedGood point - it makes more sense to move the change to CSS. On my end, it's done.
Re: getting the string to translate, I still can't figure it out. I should admit that I'm still wrapping my head around how Drupal works with t(), but looking at the documentation in:
http://api.drupal.org/api/drupal/includes%21common.inc/function/t/6
... it seems that the way lines 182 and 193 were configured before was correct, namely that the variable is = t('text') and the output merely includes the whole thing. The documentation for v7 (as opposed to v6) seems to be much less complete for some reason.
That said, there's also a strong likelihood everything you've done is perfect and I simply don't understand t() yet :-)
Thanks!
Comment #3
jrockowitz commentedI don't do any multilingual work but the basic concept is every rendered string should always be passed through the t() function which will allow it to be translated using a few related modules.
BTW, the String Overrides module (http://drupal.org/project/stringoverrides) is great example of how the t() function can be used to manipulate text.
Comment #4
shadlaws commentedGood news: you're correct that the most recent revision sends the string along for translation nicely, and it's now translated into French. No changes needed.
Bad news: although I do indeed get the basic concept of the t() command, some of the nitty-gritty specifics are still fuzzy to me :-). For example, your code seems to be an example of the "incorrect" case in the link I posted above (excerpt given below), and if I modify the code to be like the "correct" case, it stops working.
Thanks!
Shad
-------------------------------
Extraction of translations is done based on the strings contained in t() calls. If a variable is passed through t(), the content of the variable cannot be extracted from the file for translation.
Incorrect:
$message = 'An error occurred.';
drupal_set_message(t($message), 'error');
$output .= t($message);
Correct:
$message = t('An error occurred.');
drupal_set_message($message, 'error');
$output .= $message;
The only case in which variables can be passed safely through t() is when code-based versions of the same strings will be passed through t() (or otherwise extracted) elsewhere.
Comment #5
jrockowitz commentedI was not aware of this requirement for the t() function.
I will update my code to use t('Back to top').
Thanks.
Comment #6
jrockowitz commentedComment #8
marcoka commentedjust for reference. easy fontawesome usage