home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (date.views_convert.inc)

This example Drupal source code file (date.views_convert.inc) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

break, case, content_field, date_fields, day, default, field_name, month, php, string, substr, to, year

The date.views_convert.inc Drupal example source code

<?php
// $Id: date.views_convert.inc,v 1.1.2.1 2009/04/30 11:44:52 karens Exp $

/**
 * Implementation of hook_views_convert().
 */
function date_views_convert($display, $type, &$view, $field, $id = NULL) {
  static $date_fields;
  if (!isset($date_fields)) {
    $date_fields = array();
    $content_types = content_types();
    foreach ($content_types as $content_type) {
      foreach ($content_type['fields'] as $content_field) {
        if ($content_field['module'] == 'date') {
          $date_fields["$content_field[field_name]_value_default"] = 'default';
          $date_fields["$content_field[field_name]_value_year"] = 'year';
          $date_fields["$content_field[field_name]_value_month"] = 'month';
          $date_fields["$content_field[field_name]_value_day"] = 'day';
          $date_fields["$content_field[field_name]_value_to|default"] = 'to|default';
          $date_fields["$content_field[field_name]_value_to|year"] = 'to|year';
          $date_fields["$content_field[field_name]_value_to|month"] = 'to|month';
          $date_fields["$content_field[field_name]_value_to|day"] = 'to|day';
        }
      }
    }
  }
  switch ($type) {
    case 'filter':
      if (isset($date_fields[$field['field']])) {
        $item = $view->get_item($display, 'filter', $id);
        switch ($date_fields[$field['field']]) {
          case 'default':
            $field_name = substr($field['field'], 0, -14);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value');
            $item['granularity'] = 'second';
            break;
          case 'year':
            $field_name = substr($field['field'], 0, -11);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value');
            $item['granularity'] = 'year';
            break;
          case 'month':
            $field_name = substr($field['field'], 0, -12);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value');
            $item['granularity'] = 'month';
            break;
          case 'day':
            $field_name = substr($field['field'], 0, -10);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value');
            $item['granularity'] = 'day';
            break;
          case 'to|default':
            $field_name = substr($field['field'], 0, -17);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value2');
            $item['granularity'] = 'second';
            break;
          case 'to|year':
            $field_name = substr($field['field'], 0, -14);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value2');
            $item['granularity'] = 'year';
            break;
          case 'to|month':
            $field_name = substr($field['field'], 0, -15);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value2');
            $item['granularity'] = 'month';
            break;
          case 'to|day':
            $field_name = substr($field['field'], 0, -13);
            $item['date_fields'] = array('node_data_'. $field_name .'.'. $field_name .'_value2');
            $item['granularity'] = 'day';
            break;
        }
        $item['table'] = 'node';
        $item['field'] = 'date_filter';
        $item['form_type'] = 'date_text';
        $item['operator'] = $field['operator'] == '<>' ? '!=' : $field['operator'];
        if ($field['value'] == 'now' || $field['options'] == 'now') {
          $item['default_date'] = 'now';
        }
        else {
          $item['value'] = $field['value'];
          $item['default_date'] = $field['options'];
        }
        $view->set_item($display, 'filter', $id, $item);
      }
      break;
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal date.views_convert.inc source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.