0

I'm using hook_views_data in my custom module to show the formatted date of a table in mysql. Using the example in the api I have text working but my TIMESTAMP in the donationDate column shows up blank.

MySql reports it is a TIMESTAMP field and it's showing me '2015-04-16 18:41:09'. When I change out the below to the string options it shows me the string representation so I know it's passing data from that column. I've played with the options in setting up this custom view but none of the date options seem to make a difference. I've looked at Google but none point me to what I might be doing wrong. How should I troubleshoot it?

function manage_donations_views_data() {
  $data['GeneralDonations']['table']['group'] = t('Donations');
  $data ['GeneralDonations']['table']['base'] = array(
    'field' => 'donationId',
    'help' => t('List of recent donations'),
    'title' => t('All donations'),
    'weight' => -10,
  );


  $data['GeneralDonations']['donationForm'] = array('title' => t('Form'), 
    'help' => t('Form and type'), 
    'field' => array(
      'group' => 'donations',
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
      ),
      'sort' => array(
        'handler' => 'views_handler_sort', 
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ), 
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
    ));  
  $data['GeneralDonations']['donationId'] = array('title' => t('ID'), 
    'help' => t('id'), 
    'field' => array(
      'group' => 'donations',
      'handler' => 'views_handler_field', 
      'click sortable' => TRUE, 
      ),  
      'sort' => array(
        'handler' => 'views_handler_sort', 
      'filter' => array(
        'handler' => 'views_handler_filter_string',
      ), 
      'argument' => array(
        'handler' => 'views_handler_argument_string',
      ),
    ));
  $data['GeneralDonations']['donationDate'] = array('title' => t('Date'), 
    'help' => t('Date'), 
    'field' => array(
      'group' => 'donations',
      'handler' => 'views_handler_field_date', 
      'click_sortable' => TRUE,     
      ), 
    'filter' => array(
        'handler' => 'views_handler_filter_date',),
    'sort' => array(
        'handler' => 'views_handler_sort_date',
      ),
    );

  return $data;
}

The column was set up in MySql this way: donationDate TIMESTAMP

I've been using drush to clear all my cache after each code change. I have used all the options. The only one that seems to show anything is the "ago" as it shows 45 years, 4 months so it appears it recognizes the unix epoch?

Still struggling with this. Is it something wrong with how I defined the mysql field, or is it views_handler_field_date? I see some methods but unsure how to troubleshoot this. I'm unsure which to dig into? thx, sam

thx, sam

  • Do you have the Date module installed? Drupal doesn't handle date fields in core. – Darvanen May 5 '15 at 0:35
  • I didn't, I do now and have enabled it. Rechecked my settings for this field. Still blank. Thx. – sam452 May 5 '15 at 13:56
0

It appears the API is looking for an integer, particularly Unix timestamp and not the MySql timestamp which is transformed into a string. Looking at how Drupal handles the node table was key to grasping this and the hook_views_data documentation indicates that the field is an integer as well.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.