Closed (fixed)
Project:
Token
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Aug 2016 at 12:43 UTC
Updated:
5 Jan 2017 at 21:55 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
berdirtokens are defined in token module
Comment #3
Anonymous (not verified) commentedThis patch adds a desired processing format DateTime fields. It also adds an asterisk to create full anarchy in the validation of tokens :)
Example template:
events/[node:field_event_date:*:Y]/[node:field_event_date:*:m]/[node:field_event_date:*:d]/[node:title]or
events/[node:field_event_date:*:Y/m/d]]/[node:title]But in last case you should change settings in Pathauto. It is necessary to set option for Slash (/) in "No action (do not replace)".
Comment #4
berdirThanks for starting, but we don't want to duplicate logic. There are already is a date token type that can do this and also supports custom formats, using ?, not *.
What we need to do is connect the two. it should probably be similar to how we deal with entity references. Date fields have :value already, and they have a computed date property as well that currently doesn't show up. We can define that as type date and then collect nested tokens and pass them along.
Comment #5
leo pitt commented@Berdir - just to be clear: so are you saying it is already possible to set up this format of dated alias (/events/dd/mm/YYYY/title) currently via the Pathauto pattern interface?
Thanks
Comment #6
Anonymous (not verified) commented@Berdir, thank you for attention. Totally agree with you, but now I'm not clever enough for do it. Maybe later.
And yes, I also have an idea :) What about this:
1. Universal functions for all types (with cast/convert between types) :
example:
2. Expressions:
example:
3. Nesting:
These steroids are real for Token? Or rather to build own module, with nesting and expressions?)
Comment #7
berdirNo, we don't need to define some new features, the concept of nested tokens exists and that is enough. Look at how node_tokens() handles tokens like node:created:something we need the same for node:date_field:date:something.
Comment #8
Anonymous (not verified) commentedDon't forget about cache update. Example:
Comment #9
hussainwebWe could add support for daterange fields as well while we are at it.
Also, I was sure that the field's support was added in a better way than
field_tokensbut I can't remember. Of course, I might be confused considering it is a long time.Comment #10
hussainwebA small fix
Comment #11
Anonymous (not verified) commentedGreat improvement! Thank you, @hussainweb.
If the foreach can produce results twice, it is better to use the addition operation like this:
$replacements += ...I also like the idea to attach a format to the 'value' token. But the version with insulation in a new token ('format') seems more compatible solution, no?
Comment #12
berdirYes, now we're on the right path. As mentioned above, date fields have computed date properties, similar to entity on reference fields.
Lets use those for the nested tokens, so :date:... not :value:...
instead of relying on strotime, you can then use $field_item->$property->getTimestamp(). You should however check that there is indeed a validate date, just checking with if ($field_item->$property) should be enough. Test with an empty field, for example.
And then we'll need tests :)
Comment #13
hussainwebThe
valueis already provided by the core. We are just changing its type to date here.Comment #14
berdirNo, core doesn't provide any field tokens. that's all token.module.
Comment #15
leo pitt commented@Berdir - just to be clear: so are you saying it is already possible to set up this format of dated alias (/events/dd/mm/YYYY/title) currently via the Pathauto pattern interface?
Thanks
Comment #16
hussainwebThat's right. I was confused. I meant the token was defined earlier in the loop for all the tokens. And since the property name is
value, it gets that token name.I might be confused. Are you saying we should have a token like
[node:field_date:date:format]instead of[node:field_date:value:format]now? I don't see the point in that. Or do you mean a token like[node:field_date:format]? That would be slightly inconsistent with the daterange field types where there is an end date field as well.Comment #17
berdirThe point is that :date and end_date is a date object, and it makes the most sense for me to use that to pass along the formated dates, not :value.
It's exactly like target_id and entity. the token is node:some_term_field:entity:name, not node:some_term_field:target_id:name. We also explicitly define the entity token.
Comment #18
hussainwebThanks @Berdir, I think that makes sense. The patch is updated accordingly. Tests pending.
Comment #19
berdirComment #20
Anonymous (not verified) commentedRaw test, but it can be helpful to starting.
@Leo Pitt, for 'created' field is already possible, for custom field - not yet, but this dream is real :)
Comment #21
Anonymous (not verified) commentedI'm bad undestand 'daterange', but seems it haven't 'date' property, but it have 'start_date' property. It works for me (8.2.0-rc1).
Realize the rest part of #12
Maybe we need to make different UI names for 'value' and 'date' tokens (eg: ' format' postfix :)
Comment #26
Anonymous (not verified) commentedattempt to correct fail patch #21
Comment #27
Anonymous (not verified) commentedIt's me again :)
We must handle only our tokens, right?
If check by getType and list tokens, this condition seems unnecessary
If use '$property_name' and '$replacements += ', this cycle seems unnecessary
For case like '[node:field_date:date]', '[node:field_date:start_date]', '[node:field_date:end_date]'. See test.
What do you think?
Comment #34
Anonymous (not verified) commentedOk, it is bad idea. Because overriding when both variants are used simultaneously (e.g [..:date:raw] & [..:end_date]).
Possible solutions:
or skip this variant (and the process such as a value in last 'else'):
xo-xo!
Comment #35
Anonymous (not verified) commentedComment #36
jonathanshawComment #37
vyasamit2007 commentedThe patch in #35 works like a charm. Good to go.
Comment #38
Anonymous (not verified) commentedThanks! I also think that this feature is useful in many cases. And its implementation is quite isolated, so as not to damage other parts of the module. I attached one more patch. It has new tests (extends KernelTestBase) and sensible dates for daterange testing :)
Comment #43
Anonymous (not verified) commentedSorry for my stupid typos :(
Comment #44
Anonymous (not verified) commentedback to RTBC by #37, because #43 only adds tests.
Comment #45
pianomansam commentedPatch in #35 is also working for me!
Comment #47
berdirThanks everyone and sorry for the delay. Committed.
Comment #48
leo pitt commentedThanks everyone! :)