You are here

function sheetnode_views_data_alter in Sheetnode 7

Same name and namespace in other branches
  1. 6 sheetnode.views.inc \sheetnode_views_data_alter()
  2. 7.2 sheetnode.views.inc \sheetnode_views_data_alter()

Implements hook_views_data_alter().

File

./sheetnode.views.inc, line 141
Provide views data for sheetnode.

Code

function sheetnode_views_data_alter(&$data) {
  $fieldapi_info = field_info_fields();
  foreach ($data as $table_name => $table_info) {
    foreach ($table_info as $field_name => $field_info) {

      // Add a SocialCalc date converter for each date field.
      if (!empty($field_info['field']['handler']) && $field_info['field']['handler'] == 'views_handler_field_date') {
        $date = $field_info;
        $date['real field'] = $field_name;
        $date['title'] = $field_info['title'] . ' (SocialCalc)';
        $date['field']['handler'] = 'sheetnode_handler_field_date';
        unset($date['filter'], $date['argument'], $date['relationship'], $date['sort']);
        $data[$table_name][$field_name . '_socialcalc'] = $date;
      }

      // Add sheetnode handlers for each sheet field.
      if (!empty($field_info['field']['field_name']) && $fieldapi_info[$field_info['field']['field_name']]['type'] == 'sheetfield') {
        $field_info += array(
          'title short' => '',
        );
        $cell = $field_info;
        $cell['title'] = $field_info['title'] . ' (' . $field_name . ':' . t('cell') . ')';
        $cell['title short'] = $field_info['title short'] . ':' . t('cell');
        $cell['help'] = t('Cell reference') . ' - ' . $field_info['help'];
        $cell['field']['handler'] = 'sheetnode_handler_field_cell';
        $data[$table_name][$field_name . '_cell'] = $cell;
        $range = $cell;
        $range['title'] = $field_info['title'] . ' (' . $field_name . ':' . t('range') . ')';
        $range['title short'] = $field_info['title short'] . ':' . t('range');
        $range['help'] = t('Range reference') . ' - ' . $field_info['help'];
        $range['field']['handler'] = 'sheetnode_handler_field_range';
        $data[$table_name][$field_name . '_range'] = $range;
        $content = $cell;
        $content['title'] = $field_info['title'] . ' (' . $field_name . ':' . t('content') . ')';
        $content['title short'] = $field_info['title short'] . ':' . t('content');
        $content['help'] = t('Content') . ' - ' . $field_info['help'];
        $content['field']['handler'] = 'views_handler_field';
        $data[$table_name][$field_name . '_content'] = $content;
        $named_range = $cell;
        $named_range['title'] = $field_info['title'] . ' (' . $field_name . ':' . t('named range') . ')';
        $named_range['title short'] = $field_info['title short'] . ':' . t('named range');
        $named_range['help'] = t('Named range') . ' - ' . $field_info['help'];
        $named_range['field']['handler'] = 'sheetnode_handler_field_named_range';
        $data[$table_name][$field_name . '_named_range'] = $named_range;
      }
    }
  }

  // Add sheetnode editable field.
  $data['sheetnode']['sheetview_edit'] = array(
    'title' => t('Make spreadsheet editable'),
    'help' => t('Add this field to make your spreadsheet editable.'),
    'field' => array(
      'handler' => 'sheetnode_handler_field_editable',
    ),
  );
}