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 would like to use the arguments; $args[0]..$args[1]..etc..which also are used as views handling code within tokens.
Then it would be possible to have a node and refer within the node to the $args[0] etc.., right?
Thanks a lot in advance for considering this!
greetings,
Martijn
Comment | File | Size | Author |
---|---|---|---|
#62 | 273893-token-current-page-arg-tokens-D7.patch | 2.83 KB | Dave Reid |
#61 | 273893-token-current-page-arg-tokens-D7.patch | 1.13 KB | Dave Reid |
#51 | tokenArgument.zip | 1.62 KB | Summit |
#41 | token_arg_STARTER_MENU_PARTS.diff | 2.47 KB | MGN |
#28 | token_arg_STARTER_unlimited.diff | 2.5 KB | MGN |
Comments
Comment #1
greggles$args[0] is just arg(0) right?
So, yeah, we should probably support those.
Comment #2
Summit CreditAttribution: Summit commentedHow please...
I know that for argument handling code in view, you need to place $args[0] instead of arg(1), to get the arguments also working with panels. [ $args(0) = arg(1)]
Please tell me how token support arg(1) then please, and we will see how this goes further, ok?
Thanks in advance for sharing!
greetings,
Martijn
Comment #3
gregglesWell, if the args are special things in Views then the hook_token_list and hook_token_values implementations for them should happen in Views itself.
Comment #4
merlinofchaos CreditAttribution: merlinofchaos commentedUhh. $args is a special variable available in the views arg handling PHP snippet and not even related to token. This issue doesn't even make sense.
Comment #5
Summit CreditAttribution: Summit commentedHi,
As Earl described above, $args is view-internal.
So please explain please how to get arg(0) support for token, which is not views-internal I asume?
Sorry for my mistake, but I am not a pro..
Thanks in advance for your reply!
greetings,
Martijn
Comment #6
gregglesOk.
There is no way to do it now. It would require additional code - probably in token.modules token_token_list and token_token_values.
However, the dynamic nature of arg() (i.e. the fact that you can have an arbitrary number of them) means that this should probably be implemented with the whole "token 2" implementation.
If someone wanted to make a patch for arg0, arg1, arg2, and arg3 that would work for the most common cases up until that point I would be happy to commit that.
Comment #7
litwol CreditAttribution: litwol commentedSummit:
Please read the API.txt file that comes with token module. it explains how you can expose more valeus to token. one such value ofcourse can be arg(0) or arg(n).
dont open this issue again, if you have questions about how to create a module to expose those values you can ask that on the forum.
good luck.
Comment #8
greggles@litwol - I agree with most of what you said, but I think arg's are at least somewhat reasonable tokens to expose for use and the proper place for such a global token would be in token itself.
Comment #9
MGParisi CreditAttribution: MGParisi commentedId sure like to see this as a 5.x feature. Or at lease SOME way to point the current uid ($arg(1) to the path of a menu item)... I have been beating my head on this one for days, and the only solution I have heard is the best way is to use token, but how can I use token if it doesn't support arguments.
Kostly
Comment #10
colin_young CreditAttribution: colin_young commentedSo I've been able to add tokens arg0, arg1, arg2 and arg3 by adding them in the token_node.inc file. What I really wanted to do was add them to a new token_arg.inc file. I did add require_once("$path/token_url.inc"); to token.module, but the new tokens neither show up in a list of available tokens, nor do they work. In the token_node.inc file they show up in the list, and, more importantly, they work.
I'm sure I'm just missing some little step, but even reviewing other modules and how they define tokens hasn't enlightened me.
Any suggestions?
Thanks.
P.S. I'd rather see something like [arg:0] or [arg(0)] or some such thing that would allow an argument to be passed with the token. I gather from one of the comments that such a thing might be coming in a new version of token?
Comment #11
greggles@colin_young - if you post the non-working code as a patch then we can discuss why it isn't working.
And...while [arg:0] are a good idea it's probably not in the timeframe for adding this patch to this module.
Comment #12
colin_young CreditAttribution: colin_young commented@greggles - Sure. Attaching the files here. (Is there some way to create a patch containing multiple files without CVS? I really should install some sort of revision control -- or just start using my subversion installation :) -- but I really hadn't been planning on mucking about in drupal code.)
My comment about a future version supporting arg:0 was prompted by your comment about a "token 2" module, which, I'm guessing, is way off in the future. I assume that arg0, arg1, etc. is a hack that would be retired if/when a token 2 module was released.
Comment #13
Summit CreditAttribution: Summit commentedHi,
I installed this patch..but I do not see the arguments as tokens, sorry.
I tried bringing them on board token_node.inc, but didn't succeeded either.
I read your remarks:
So I've been able to add tokens arg0, arg1, arg2 and arg3 by adding them in the token_node.inc file
Do you have may be your token_node.inc solution for me?
In your remarks you refer to token_arg.inc (I do not see this in the patch).
Of course also very much interested in the best solution to be able to use the url-arguments as tokens in nodes.
Thanks a lot for your reply!
greetings,
Martijn
Comment #14
gregglesIn fact, these are probably global tokens that should be added to token.module's hook_token_list and hook_token_values if added anywhere. That should eliminate the include problems.
Comment #15
colin_young CreditAttribution: colin_young commented@Summit - token_arg.inc was a file name I started with before I realized it should be called token_url, or as greggles suggests, put into a more appropriate existing token file. I'm going to make those changes now and submit a new patch.
Comment #16
colin_young CreditAttribution: colin_young commented@greggles - took your suggestion and trying again.
Comment #17
Summit CreditAttribution: Summit commentedHi,
Tokens fot argument are working now with this patch.
The only problem is with aliased url's still.
So my url www.example.com/Nepal/Kathmandu/flight is "inside drupal" www.example.com/taxonomy/term/4
So as token-value for arg2 = 4 and not flight..
greetings,
Martijn
Comment #18
MGN CreditAttribution: MGN commentedTo handle aliases, you can use drupal_get_path_alias($_GET['q']) and then run the returned path through arg to get the components.
This patch provides [argX] and [argX-alias] tokens, where X can be 0, 1, 2, ... up to a defined value (so you can have as many args as you want, but I left the maximum at 4 as in colin_young's patch).
Comment #19
MGN CreditAttribution: MGN commentedupdating status to reflect the new patches in #16 and #18
Comment #20
barry CreditAttribution: barry commentedsubscribing
Comment #21
jenlamptonPatch works for me. Thanks for all your work on this, it's an excellent addition!
Jen
Comment #22
gregglesHere's a new version against the token starter kit. Otherwise it is copy and paste and untested.
@MGN, @jenlampton - Thanks for your work. Drupal's coding standard is generally not to use inline comments and to make comments full sentences with a capital letter and a period on the end, so not quite RTBC ;)
Comment #23
MGN CreditAttribution: MGN commentedThanks greggles. I think the starter kit is a good idea and a good place for these tokens.
It looks like you copied and pasted the code snippets into the wrong functions (swapping token_list and token_values). Here is a new patch that fixes this problem.
Comment #24
a_c_m CreditAttribution: a_c_m commentedThis patch is a critical part of a module i'm writing called Custom Reports (http://drupal.org/project/customreports) - subscribing.
Comment #25
MGN CreditAttribution: MGN commented@a_c_m, does this mean that you have tested the patch in #23 and can confirm that it is working?
Comment #26
a_c_m CreditAttribution: a_c_m commentedNot quite.
But the code itself worked fine. I would quite like to see it not need TOKEN_NUM_ARG_TOKENS and instead just work out how many args there are in the current request and use them.
Perhaps also allow for named arguments e.g. /node/123?name=frank then being able to use [arg-name] etc etc
I've attached the patch re-rolled to apply cleanly to the latest revision.
Comment #27
gregglesAgreed. Marking needs work for that.
So, [arg-name] would contain "frank" ? That seems like a query string parameter, not an "arg" and therefore a different feature request. I'm also not sure that belongs in the STARTERKIT.
Comment #28
MGN CreditAttribution: MGN commentedI agree with greggles on the query - its not part of the url...
Here is a leaner patch that doesn't require that constant.
Comment #29
j_ten_man CreditAttribution: j_ten_man commentedTested MGN's patch (#28) and it works as expected.
Comment #30
litwol CreditAttribution: litwol commentedI tested patch in #28 and it worked as expected, tests conduced under E_ALL and no notices/errors were generated. i used automatic node titles module to test this.
token used: [arg0]-[arg1]-[arg2]-[arg3]
node title generated: node-2-edit-[arg3]
Comment #31
litwol CreditAttribution: litwol commentedMissed to change status.
Comment #32
apadernoWould not it better if the code could replace "[arg-3]" with an empty string, if the argument does not exist? If I call
arg(3)
in such case, I would get a NULL value.Comment #33
gregglesI now agree with Kiam, but I'm unsure how to do this. How far up through args should we go getting null values? To 10?
Comment #34
MGN CreditAttribution: MGN commentedTo do what Kiam suggests would require defining some arbitrary constant to do a null token replacement, which greggles and a_c_m didn't seem to like. There will probably be a slight performance hit, but probably insignificant. Its easy enough to do.
Just tell me what arbitrary number of arg tokens we want to null out, and I can create a new patch.
Also, it seems the default is for tokens to go untranslated if there is no replacement value. Sometimes this results in an annoying [token] popping up where you would prefer to have nothing at all.
So perhaps its worth considering if token_replace (et al.) should be altered to automatically filter out any untranslated tokens?
Comment #35
MGN CreditAttribution: MGN commentedoops. cross posted with greggles.
Comment #36
gregglesMy feeling here is that hook_token_values modules should default to '' and then put in the value when necessary. The reason being:
1. I don't want to make token replacement any more complex than it has to be for performance reasons.
2. There are legitimate reasons to use text like "[something]" and want it to not be replaced with an empty string.
I am very sorry to have changed my mind on this issue - @MGN - are you up for one final re-roll? Thanks!
Comment #37
MGN CreditAttribution: MGN commentedI agree. I realized after I made the suggestion that other modules also use square brackets as a signature and nulling out [something] would certainly interfere with those modules. Anyway, I am happy to do as many rerolls as it takes - not a problem. Its better to get it right.
Since its in tokenSTARTER and designed to be modified, the actual value I assign to TOKEN_NUM_ARG_TOKENS doesn't really matter, though it would be best if it worked as expected in most circumstances. I think 10 is a fine number.
Are we settled on nulling out [arg-N] for unset arguments through [arg-10] ?
Comment #38
apadernoWhat I was thinking of is the Drupal core code that passes
$arg
tohook_help()
; if I remember well, that argument is an array with X elements, which by default are empty strings.The called function executes the following code:
Comment #39
apadernoI think there is already a constant for the maximum number of parts a menu string should be made of; it should be also the maximum value accepted by
arg()
.EDIT:
arg()
doesn't set a limit for the$index
argument it accepts, but it's more probable that passing a value higher thanMENU_MAX_PARTS
the function doesn't return a value at all.Comment #40
gregglesYes, it seems our constant can be based on MENU_MAX_PARTS.
Comment #41
MGN CreditAttribution: MGN commentedHere is a patch that creates a fixed number of arg tokens, based on the value of MENU_MAX_PARTS. All [argN] and [argN-alias] tokens will return null when arg itself returns null.
Still, I am not completely convinced that basing the number of tokens on MENU_MAX_PARTS make sense.
As Kiam points out, arg() itself doesn't set a limit. And I have verified that you can use arg() to retrieve as many parts of the url as you like (I tested up to 10) for use in a module callback page. Its true that only the first MENU_MAX_PARTS of the path will be used in identifying the menu item in the menu_router table. But that doesn't mean that module developers won't use arg() directly and exceed this limit.
Then again, MENU_MAX_PARTS is defined as 7, and this should cover most cases just fine.
Comment #42
MGParisi CreditAttribution: MGParisi commentedThis is a one year old issue. I am happy people are working on this and I would love to see this feature but maybe we have gone about this the wrong way.
Maybe we need to first include the ability to add variables to people who create tokens? For instance, I may want to create a token [comment-42]. I think doing this would ultimately solve a multitude of issues (and ultimately close this ticket).
Comment #43
MGN CreditAttribution: MGN commented@MGParisi. I am not sure if I understand what are looking for, but using the tokenSTARTER module, you can create your own custom tokens.
This doesn't seem to be related to the current issue, so you might think about opening a new issue if you want to develop the idea further.
I am interested in "closing this ticket" however.
A couple of months ago greggles asked for the re-roll in #41. Anyone willing to test it so we can move to RTBC?
Comment #44
libeco CreditAttribution: libeco commentedI have used the patch in #41 to solve an issue I had with Custom Breadcrumbs, as can be seen here: Taxonomy breadcrumb with the taxonomy view. So I can confirm this works.
Comment #45
ecksley CreditAttribution: ecksley commentedMe too. Working fine.
Thank you!
Comment #46
Summit CreditAttribution: Summit commentedHi,
Could this patch of #41 go in please. And would it be able to add them to the global tokens?
Thanks a lot in advance for considering!
greetings,
Martijn
Comment #48
Summit CreditAttribution: Summit commentedHi, Is the failure about name conventions, like stated here: http://drupal.org/node/343487#comment-3129952
Please file a new patch to get this in. I am not in the situation behind pc with patch support.
greetings, Martijn
Comment #49
MGN CreditAttribution: MGN commentedI can work on this again if the maintainers would be interesting in moving this forward.
Comment #50
Summit CreditAttribution: Summit commentedHi,
I would love to have arg() as global tokens, this way they can be used in nodewords etc..
Thanks in advance for considering working on it again!
greetings,
Martijn
Comment #51
Summit CreditAttribution: Summit commentedHi,
I build the TokenArgument.module from the patch http://drupal.org/files/issues/token_arg_STARTER_MENU_PARTS.diff and named it tokenArgument.module.
I attach the zipfile. It is working great!
Greetings,
Martijn
Comment #52
Dave ReidNew tokens need to be put into D7 first, then backported. Still not sure sold on this token.
Comment #53
gregglesWhy not stick it in the tokenstarterkit or the examples module?
That's the home for things we are unsure of and it seems we are still unsure of it.
Comment #54
Summit CreditAttribution: Summit commentedHi,
+1 to put it in TokenSTARTER.module.
I had to stick it also in this module to get it working generic. So rename TokenARGUMENT to TokenSTARTER in above zip.
greetings,
Martijn
Comment #55
Dave ReidI guess it would actually make a lot of sense to add a new 'Current page' grouping in D7 tokens, where we can put stuff like args, query strings, canonical urls, etc.
Comment #56
gregglesYeah, I can see the benefit of that broader group.
Comment #57
codegoat CreditAttribution: codegoat commented#12: token.module.patch queued for re-testing.
Comment #58
wxman CreditAttribution: wxman commentedDoes anyone know if this same idea could be used with a taxonomy tags list?
I'm trying to find a way to use a token in nodewords for an Authors taxonomy entry to use in a meta tag. The field can have a single name, or several. I've been able to edit template.php so to completely theme my taxonomy output, including adding to $vars a new $authors variable so I can output a comma separated list of the names.
I tried to experiment with a modified version of what was tried in #51, but it didn't work. I would love to hear if anyone has any ideas.
Comment #59
Cyberwolf CreditAttribution: Cyberwolf commentedSubscribing.
Comment #60
aaron.r.carlton CreditAttribution: aaron.r.carlton commentedsubscribing
Comment #61
Dave ReidComment #62
Dave ReidComment #63
Dave ReidCommitted #62 to CVS! http://drupal.org/cvs?commit=451680
Comment #64
dobe CreditAttribution: dobe commentedsubscribe.
Comment #65
brunorios1 CreditAttribution: brunorios1 commentedsub
Comment #66
Summit CreditAttribution: Summit commentedHi, more than a year later, is this patch #62 ported to D6?
If so thanks, and sorry to disturb.
greetings,
Martijn
Comment #67
apadernoI am closing this issue since it's for a Drupal version that isn't supported.