Closed (fixed)
Project:
Custom Formatters
Version:
6.x-1.4-beta2
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
22 Feb 2010 at 07:41 UTC
Updated:
6 Apr 2010 at 01:35 UTC
I created a basic Custom Formatter for a CCK Date field and it just displays the name of the token and not the substituted value.
The basic custom formatter text (field type Date):
Selection for the month of [field_month-month] [field_month-yyyy]
"field_month" is the name of a CCK Date field in a content type. [field_month-month] [field_month-yyyy] are tokens listed in the "CCK date tokens" section. What am I doing wrong?
Pertinent modules list:
Custom Formatters 6.x-1.4-beta1
Date and Date API 6.x-2.x-dev
Devel Generate (for the preview feature) 6.x-1.18
Token 6.x-1.12
Comments
Comment #1
decipheredOk, so the issue is actually quite simple, the previews are based on randomly generated values provided by the Devel Generate module, which will not give you an exact representation of a node, considering the node type is also randomly chosen you may not even get the type that has the particular field you desired. This is something I am looking into a fix for, and will likely be in by the stable 1.4 release.
In the short term, the latest devel version has the following warning, which would have helped you out:
So testing the formatter on an actual node would have different, likely more positive results.
However, another thing to take into account is that you are referring to the node version of the token, not the field version, what this means is that if you where to have multiple values for your field, the node token would return only the first value, whereas the field token would return the value of the current field that is being formatted. This isn't specifically a problem, but it is something you may want to take into account, and it would give you a better preview result at this stage.
Hope this helps.
Cheers,
Deciphered.
Comment #2
decipheredI just released 6.x-1.4-beta2 which now gives you the ability to select what node type you would like to use for the preview of your formatter and will now replace the particular tokens that you where using (in preview, they should already have worked on a real piece of content).
Check it out and let me know how it goes. If there are no further bugs reported in the next few days I will push out the stable release.
Cheers,
Deciphered.
P.S. See what happens when you post the issue in a developers issue queue ;)
Comment #3
shiva7663 commentedIt didn't work on a real piece of content, but I'll give the new version a try.
Comment #4
decipheredHmm, if it didn't work on a real piece of content it implies that there may be more to the problem. My initial thinking is that the token in question may not be being populated for some reason (No data to populate it with, incorrect spelling of token, any number of other possible reasons), but I can't be sure of the exact cause without more information.
Let me know how you go with the new version and we can go from there.
Cheers,
Deciphered.
Comment #5
shiva7663 commentedUsing a custom format of "[field_month-month] [field_month-yyyy] and [field_month-value]" works in Preview, works in a basic node with data of the correct content type, but does not work when nodes of that content type are collected in a View (v6.x-2.8). What additional information should I include?
Comment #6
shiva7663 commentedHere's a sample view that demonstrates the issue:
Comment #7
decipheredshiva7663,
Thanks for the test data, makes things a lot easier for me. Or it would if it reproduced the issue, but unfortunately for you, I was unable to reproduce the issue. It worked perfectly for me.
Did you have an success using the latest release?
Cheers,
Deciphered.
Comment #8
shiva7663 commentedThe actual date saved in the field (with year, month granularity) is 2010-04. The raw data of the date is 2010-04-00T00:00:00
The basic custom format is:
[field_demodate-month] [field_demodate-yyyy] and [field_demodate-value] or [month] [yyyy].When displayed as a node:
April 2010 and 2010-04-00T00:00:00 or April 2010.When displayed on the Demo Page's content node as a block created by a view (placed in the footer region):
April 2010 and 2010-04-00T00:00:00 or February 2010.When displayed on any other node of the site as a block created by a view (placed in the footer region):
[field_demodate-month] [field_demodate-yyyy] and [field_demodate-value] or March 2010.So, this works as expected (for me) only in the case where the demo page content is displayed as a simple node. The second case is good for that one node of the site, but [month] shows as the wrong month. For the rest of the site the field tokens don't translate, and the [month] token also gives a (different) wrong value.
I generated a Feature plugin, but it looks like the Feature module doesn't handle exporting basic custom formatters. I might try converting the basic one into an advanced one so that it could be exported, though. Not sure that would help.
Comment #9
deciphered[field_demodate-month] and [month] point to two different object, the first being the first date field of a node, and the second being the current field being formatted, so it is possible that these two fields would be different. In my case, in all tests, they where the same.
As for the third result, my tests did also work as expected here, but it is possible that the reason yours didn't is that the object being passed to the formatter does not actually contain the correct field for the token, yet does have a field or value that is resulting in [month] and [yyyy] tokens.
I realize that this response is extremely unhelpful, but as I am unable to reproduce the issue it is hard to give much else. I don't like asking, but if it is possible to reproduce the issue on a clean drupal install then zip the files and a database dump and email them to me, that would be extremely helpful. Just send a quick message to me via my D.o. contact form and I'll pass on my email address.
Cheers,
Deciphered.
Comment #10
shiva7663 commentedBleargh, I forgot to mention that whenever I try to edit that particular custom formatter, it throws errors:
I'm working on a simple test zip now; so far it gives me the same results as before. (Note to self, test zip sent 25 FEB 2010)
Comment #11
shiva7663 commentedUpdated these modules:
Custom Formatters 6.x-1.5-beta1
Date 6.x-2.x-dev (2 MAR 2010)
No change in test results.
Comment #12
decipheredWell the problem is that the tokens you are using and the view type you are using aren't compatible. You're using Node tokens with a Field, so the token replacement isn't getting a node object to take the values from.
If you use the Field Tokens instead, it will work.
Your current formatter is:
Change it to:
Or alternatively, use a Node view.
Cheers,
Deciphered.
Comment #13
shiva7663 commentedI was under the impression that, because the tokens were in the "CCK Date" section and had "field_" followed by the name of the CCK field I was accessing, I was using Field Tokens. Using [month] and [yyyy] would gather information from the Node, which could be quite different from the date I actually want to use from the CCK Date field.
If I do use [month] and [yyyy], how does it know to replace data from field_mydate and not some other CCK Date field I might also have in the node? Do you see what I mean?
Comment #14
decipheredAs you define which field uses which formatter, the only way the formatter could get the wrong field is if you set the formatter to be used on a field you didn't wish the formatter to use. So in other words, it can't get the wrong field values, it can only get the fields values that you give it.
Hope this helps.
Cheers,
Deciphered.
Comment #15
shiva7663 commentedThanks, testing today, will post results.
Comment #16
shiva7663 commentedAs a test, I expanded the date field to use full granularity (instead of just year and month) to see if that would shed some light on why it's giving me the wrong month, and found that in several of the different cases, instead of June 2011, it was actually displaying 7pm, May 31st, 2011 instead. I'll keep fiddling with this, but at some point, I'll need to move on.
Comment #17
shiva7663 commentedAre you still getting perfect results and no error messages? If so, I've got to wonder what's different about your setup and mine from the .zip I sent in.
Comment #18
decipheredYes it works for me.
Did you make the token changes I suggested? If not, I can't help.
Cheers.
Deciphered.
Comment #19
shiva7663 commentedThe token text I am currently using is:
<em>[month]</em> <u>[yyyy]</u> <strong>[value]</strong>Under "preview" it gives correct output, but still shows these errors:
The date I've set in the Custom Page example node is 2011-06, which displays correctly when the whole node is displayed. It gets pear-shaped when the fields from that node are used in a Views Block, where the date custom formatter displays the [month] token as the previous month:
May 2011 2011-06-00T00:00:00
Here is an export of the custom_block View:
It's no longer exhibiting the 7pm behavior I noted in #16 (I set the granularity of the content type back to Year Month).
Comment #21
shiva7663 commentedThe issue was not actually fixed, but now I'm investigating to see if the Date issue at http://drupal.org/node/313704 is what may actually be causing the incorrect token problem for me.