Closed (works as designed)
Project:
Custom Formatters
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Jan 2012 at 14:10 UTC
Updated:
24 Feb 2012 at 21:54 UTC
I did a formatter (code) to work with tokens. I needed that just because I dont know how to get the base_path in basic mode (is it possible? is there a token to the base_path?).
$code = '<a class="colorbox colorbox-insert-image" href="' . base_path() . '[filefield-filepath]" rel="gallery-all" title="[filefield-title]"><img alt="[filefield-alt]" class="imagecache imagecache-post legendacinza" src="' . base_path() . '[filefield-imagecache-post]" style="float: right;" title="[filefield-title]" /></a>';
$formatter = is_object($element['#formatter']) ? $element['#formatter'] : custom_formatters_formatter($element['#formatter']);
$formatter->code = $code;
return _custom_formatters_token_replace($formatter, $element);
Is this correct? Is this the best approach?
Is it possible to have this feature natively?
Thanks!!!
[EDITED - Typo, grammar, etc...sorry, english is not my first language]
Comments
Comment #1
soulfroysOh boy... works only with the first loaded image. Returning to my "hard" coded without tokens:
Comment #2
iantresman commentedI expressed a similar request in my post "Custom Formatters: use token in PHP".
Perhaps all that is required is a simple explanation of how to produce the appropriate PHP code from a token. If I know that the token is "[node-title]", how can I either
ie. $nodetitle = convtoken("[node-title]");
It seems that "Basic" mode has access to tokens, so I presume that it uses a snippet to convert from tokens to something more usable in PHP?
Comment #3
soulfroysI spoke too soon... the "Convert" option does just that. :)
The correct syntax is:
Comment #4
iantresman commentedWell spotted! For the benefit of others, when you create a new BASIC custom format and list it in the summary table, one of the operations is "Convert". This converts a BASIC custom format into the equivalent ADVANCED PHP format, with the necessary code.
Unless you create your own BASIC formatter, you'd never know there was Convert option.
Comment #4.0
iantresman commentedTypo, grammar, etc...sorry, english is not my first language.