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

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

This example Drupal source code file (upload.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

array, break, case, display, field, filter, id, item, node, node_upload_fid, relationship, switch, true, upload_fid

The upload.views_convert.inc Drupal example source code

<?php
//$Id: upload.views_convert.inc,v 1.4.4.1 2009/11/02 22:01:26 merlinofchaos Exp $

/**
 * @file
 * Field conversion for fields handled by this module.
 */

/**
 * Implements hook_views_convert().
 *
 * Intervene to convert field values from the Views 1 format to the
 * Views 2 format. Intervene only if $view->add_item() won't produce
 * the right results, usually needed to set field options or values.
 */
function upload_views_convert($display, $type, &$view, $field, $id = NULL) {
  switch ($type) {
    case 'field':
      switch ($field['tablename']) {
        case 'file_revisions':
          switch ($field['field']) {
            case 'fid':
              $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid');
              $view->set_item_option($display, 'field', $id, 'relationship', $relationship);
              $view->set_item_option($display, 'field', $id, 'table', 'files');
              break;
          }
          break;
        case 'files':
          switch ($field['field']) {
            case 'all_files':
              $item = $view->get_item($display, 'field', $id);
              switch ($field['options']) {
                case 'link':
                  $item['link_to_file'] = TRUE;
                  break;
                case 'linkdesc':
                  $item['link_to_file'] = TRUE;
                case 'nolinkdesc':
                  $item['alter']['alter_text'] = TRUE;
                  $item['alter']['text'] = '['. $view->add_item($display, 'field', 'upload', 'description', array('exclude' => TRUE)) .']';
                  break;
              }
              if ($field['handler'] == 'views_handler_file_listed_files') {
                $item['only_listed'] = TRUE;
              }
              $item['table'] = 'node';
              $item['field'] = 'upload_fid';
              $view->set_item($display, 'field', $id, $item);
              break;
            case 'filename':
              if ($field['handler'] == 'views_handler_file_filename_download') {
                $view->set_item_option($display, 'field', $id, 'link_to_file', TRUE);
              }
              $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid');
              $view->set_item_option($display, 'field', $id, 'relationship', $relationship);
              break;
          }
          break;
      }
      break;
    case 'filter':
      switch ($field['tablename']) {
        case 'file_revisions':
          switch ($field['field']) {
            case 'fid':
              $view->set_item_option($display, 'filter', $id, 'table', 'node');
              $view->set_item_option($display, 'filter', $id, 'field', 'upload_fid');
              break;
            case 'list':
              $view->set_item_option($display, 'filter', $id, 'table', 'upload');
              break;
          }
          break;
        case 'files':
          switch ($field['field']) {
            case 'filename':
            case 'filemime':
              $item = $view->get_item($display, 'filter', $id);
              $item['operator'] = $field['operator'];
              $item['case'] = FALSE;
              $item['relationship'] = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid');
              $view->set_item($display, 'filter', $id, $item);
              break;
            case 'filesize':
              $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid');
              $view->set_item_option($display, 'filter', $id, 'relationship', $relationship);
              $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']);
              break;
          }
          break;
      }
      break;
    case 'sorts':
      switch ($field['tablename']) {
        case 'file_revisions':
          switch ($field['field']) {
            case 'fid':
              $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid');
              $view->set_item_option($display, 'field', $id, 'relationship', $relationship);
              $view->set_item_option($display, 'field', $id, 'table', 'files');
              break;
          }
          break;
      }
      break;
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal upload.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.