You are here

flashnode.views.inc in Flash Node 5.6

File

flashnode.views.inc
View source
<?php

/**
 * Implementation of hook_views_tables
 */
function flashnode_views_tables() {

  // Provide access to the flash content
  $tables['flashnode'] = array(
    'name' => 'flashnode',
    'join' => array(
      'left' => array(
        'table' => 'node',
        'field' => 'vid',
      ),
      'right' => array(
        'field' => 'vid',
      ),
    ),
    'fields' => array(
      'content' => array(
        'name' => t('Flash node: Content'),
        'sortable' => FALSE,
        'notafield' => TRUE,
        'option' => array(
          '#type' => 'textfield',
          '#size' => 10,
        ),
        'handler' => 'flashnode_views_handler_field_content',
        'help' => t('Display the flash content from this node. You can pass options using the flash node input filter syntax.'),
      ),
    ),
  );

  // Provide access to the flash file data
  $tables['flashnode_filename'] = array(
    'name' => 'files',
    'join' => array(
      'left' => array(
        'table' => 'flashnode',
        'field' => 'fid',
      ),
      'right' => array(
        'field' => 'fid',
      ),
    ),
    'fields' => array(
      'filepath' => array(
        'name' => t('Flash node: Path'),
        'sortable' => TRUE,
        'help' => t('Display the file path for the flash content from this node.'),
      ),
    ),
    'filters' => array(
      'filepath' => array(
        'name' => t('Flash node: Path'),
        'operator' => 'views_handler_operator_like',
        'handler' => 'views_handler_filter_like',
        'help' => t('Filter based on the flash node file path.'),
      ),
    ),
  );
  return $tables;
}

/**
 * Handler for displaying a flash file from a given nid, with optional
 * string of parameters in flash node input filter format
 */
function flashnode_views_handler_field_content($fieldinfo, $fielddata, $value, $data) {

  // If options passed then turn options string in to an array
  $options = array();
  if ($fielddata['options']) {
    $options = array_map('trim', explode('|', $fielddata['options']));
  }

  // Initialise data array with the nid
  $data = array(
    'nid' => $data->nid,
  );

  // Add on any options
  foreach ($options as $option) {
    $pos = strpos($option, '=');
    $data_name = substr($option, 0, $pos);
    $data_value = substr($option, $pos + 1);
    $data[$data_name] = $data_value;
  }

  // Generate flash node markup
  return flashnode_content($data);
}

Functions

Namesort descending Description
flashnode_views_handler_field_content Handler for displaying a flash file from a given nid, with optional string of parameters in flash node input filter format
flashnode_views_tables Implementation of hook_views_tables