Project:Custom Formatters
Version:6.x-1.4-beta2
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

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

#1

Ok, 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:

Note: Be aware that previews are only available if a module provides support for Devel Generate and is not guaranteed to be an exact representation of the formatter. It is recommended to test the formatter on an active node for the best results.

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.

#2

Title:Custom Formatter tokens not substituting correctly» Custom Formatters Preview not replacing Node Field tokens.
Version:6.x-1.4-beta1» 6.x-1.4-beta2
Status:active» fixed

I 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 ;)

#3

It didn't work on a real piece of content, but I'll give the new version a try.

#4

Title:Custom Formatters Preview not replacing Node Field tokens.» Tokens not being replaced?
Status:fixed» active

Hmm, 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.

#5

Using 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?

#6

Here's a sample view that demonstrates the issue:

Basic Custom Format: feature_date
Field type: Date
HTML: [field_demodate-month] [field_demodate-yyyy] and [field_demodate-value] or [month] [yyyy].

Demo Date field in Demo Page content type:
Label: Demo Date
Widget type: Select List
Default Value: Now
Default value for To date: Same as From date
Granularity: Year, Month
Time zone handling: No time zone conversion
other configuration items are defaults

$view = new view;
$view->name = 'demo_block';
$view->description = 'Demo Block';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'body' => array(
    'label' => 'Body',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
    'relationship' => 'none',
  ),
  'field_demodate_value' => array(
    'label' => '',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'label_type' => 'none',
    'format' => 'custom_formatters_feature_date',
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => TRUE,
    ),
    'repeat' => array(
      'show_repeat_rule' => '',
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'exclude' => 0,
    'id' => 'field_demodate_value',
    'table' => 'node_data_field_demodate',
    'field' => 'field_demodate_value',
    'relationship' => 'none',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'demo_page' => 'demo_page',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler = $view->new_display('block', 'Demo Page Block', 'block_1');
$handler->override_option('block_description', 'Demo Page Block');
$handler->override_option('block_caching', -1);

#7

shiva7663,

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.

#8

The 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.

#9

[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.

#10

Bleargh, I forgot to mention that whenever I try to edit that particular custom formatter, it throws errors:

* recoverable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\customtest\sites\all\modules\date\date\date.module on line 557.
* warning: array_pop() [function.array-pop]: The argument should be an array in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 790.
* warning: array_pop() [function.array-pop]: The argument should be an array in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1360.
* warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1362.
* warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1365.
* warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1368.

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)

#11

Updated these modules:

Custom Formatters 6.x-1.5-beta1
Date 6.x-2.x-dev (2 MAR 2010)

No change in test results.

#12

Status:active» fixed

Well 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:

<em>[field_mydate-month]</em> <u>[field_mydate-yyyy]</u> <strong>[field_mydate-value]</strong>

Change it to:

<em>[month]</em> <u>[yyyy]</u> <strong>[value]</strong>

Or alternatively, use a Node view.

Cheers,
Deciphered.

#13

I 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?

#14

As 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.

#15

Thanks, testing today, will post results.

#16

As 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.

#17

Are 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.

#18

Yes it works for me.

Did you make the token changes I suggested? If not, I can't help.

Cheers.
Deciphered.

#19

The 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:

recoverable fatal error: Object of class stdClass could not be converted to string in C:\xampp\htdocs\customtest\sites\all\modules\date\date\date.module on line 557.
warning: array_pop() [function.array-pop]: The argument should be an array in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 790.
warning: array_pop() [function.array-pop]: The argument should be an array in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1360.
warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1362.
warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1365.
warning: in_array() [function.in-array]: Wrong datatype for second argument in C:\xampp\htdocs\customtest\sites\all\modules\date\date_api.module on line 1368.

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:

$view = new view;
$view->name = 'custom_block';
$view->description = 'Custom Block';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'teaser' => array(
    'label' => 'Teaser',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'teaser',
    'table' => 'node_revisions',
    'field' => 'teaser',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'type' => array(
    'label' => 'Type',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('items_per_page', 1);
$handler->override_option('row_options', array(
  'inline' => array(
    'title' => 'title',
    'type' => 'type',
    'field_mydate_value' => 'field_mydate_value',
  ),
  'separator' => '',
  'hide_empty' => 0,
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('fields', array(
  'teaser' => array(
    'label' => 'Teaser',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'exclude' => 0,
    'id' => 'teaser',
    'table' => 'node_revisions',
    'field' => 'teaser',
    'relationship' => 'none',
  ),
  'title' => array(
    'label' => 'Title',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'relationship' => 'none',
  ),
  'type' => array(
    'label' => 'Type',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'exclude' => 0,
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'relationship' => 'none',
  ),
  'field_mydate_value' => array(
    'label' => 'This is a test',
    'alter' => array(
      'alter_text' => 0,
      'text' => '',
      'make_link' => 0,
      'path' => '',
      'link_class' => '',
      'alt' => '',
      'prefix' => '',
      'suffix' => '',
      'target' => '',
      'help' => '',
      'trim' => 0,
      'max_length' => '',
      'word_boundary' => 1,
      'ellipsis' => 1,
      'strip_tags' => 0,
      'html' => 0,
    ),
    'empty' => '',
    'hide_empty' => 0,
    'empty_zero' => 0,
    'link_to_node' => 0,
    'repeat' => array(
      'show_repeat_rule' => '',
    ),
    'multiple' => array(
      'multiple_number' => '',
      'multiple_from' => '',
      'multiple_to' => '',
      'group' => TRUE,
    ),
    'fromto' => array(
      'fromto' => 'both',
    ),
    'label_type' => 'custom',
    'format' => 'custom_formatters_month_year',
    'exclude' => 0,
    'id' => 'field_mydate_value',
    'table' => 'node_data_field_mydate',
    'field' => 'field_mydate_value',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('block_description', 'Custom Block');
$handler->override_option('block_caching', -1);

It's no longer exhibiting the 7pm behavior I noted in #16 (I set the granularity of the content type back to Year Month).

#20

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

#21

The 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.