View source
<?php
function availability_calendar_field_views_data_alter(&$data, $field, $module) {
if ($field['type'] == 'availability_calendar') {
$field_name = $field['field_name'];
$field_table_name = key($field['storage']['details']['sql']['FIELD_LOAD_CURRENT']);
$revision_table_name = key($field['storage']['details']['sql']['FIELD_LOAD_REVISION']);
$entity_types = array_keys($field['bundles']);
$field_views_info = $data[$field_table_name][$field_name];
$field_title = $field_views_info['title'];
$join_extra = array(
array(
'table' => $field_table_name,
'field' => "{$field_name}_enabled",
'value' => 1,
'numeric' => TRUE,
),
);
unset($data[$revision_table_name]);
$data[$field_table_name]["{$field_name}_cid"] = array(
'group' => $field_views_info['group'],
'title' => t('@field_label available', array(
'@field_label' => $field_title,
)),
'title short' => t('@field_label available', array(
'@field_label' => $field_title,
)),
'help' => t('Filters on availability during the defined period.') . ' ' . $field_views_info['help'],
'argument' => array(
'field' => "{$field_name}_cid",
'field_name' => "{$field_name}_cid",
'table' => $field_table_name,
'handler' => 'availability_calendar_handler_argument_availability',
'default_state' => $field['settings']['default_state'],
'allocation_type' => $field['settings']['allocation_type'],
),
'filter' => array(
'field' => "{$field_name}_cid",
'field_name' => "{$field_name}_cid",
'table' => $field_table_name,
'handler' => 'availability_calendar_handler_filter_availability',
'default_state' => $field['settings']['default_state'],
'allocation_type' => $field['settings']['allocation_type'],
),
);
$data[$field_table_name]["{$field_name}_name"]['title'] = t('@field_label name', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_name"]['title short'] = t('@field_label name', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_name"]['help'] = t('The name of the calendar', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_enabled"]['title'] = t('@field_label enabled', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_enabled"]['title short'] = t('@field_label enabled', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_enabled"]['help'] = t('Whether the calendar has been enabled', array(
'@field_label' => $field_title,
));
$data[$field_table_name]["{$field_name}_enabled"]['filter']['handler'] = 'views_handler_filter_boolean_operator';
$table_availability_calendar_calendar = array();
foreach ($entity_types as $entity_type) {
$table_availability_calendar_calendar['table']['join'][$entity_type] = array(
'table' => 'availability_calendar_calendar',
'left_table' => $field_table_name,
'left_field' => "{$field_name}_cid",
'field' => 'cid',
'extra' => $join_extra,
);
}
$table_availability_calendar_calendar['created'] = array(
'group' => $field_views_info['group'],
'title' => t('@field_label created date', array(
'@field_label' => $field_title,
)),
'title short' => t('@field_label created', array(
'@field_label' => $field_title,
)),
'help' => t('The date the calendar was created.') . ' ' . $field_views_info['help'],
'field' => array(
'field_name' => 'created',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
'element type' => 'span',
),
'argument' => array(
'field' => 'created',
'field_name' => 'created',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_argument_date',
),
'filter' => array(
'field' => 'created',
'field_name' => 'created',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_filter_date',
'allow empty' => FALSE,
),
'sort' => array(
'field' => 'created',
'field_name' => 'created',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_sort_date',
),
);
$table_availability_calendar_calendar['changed'] = array(
'group' => $field_views_info['group'],
'title' => t('@field_label updated date', array(
'@field_label' => $field_title,
)),
'title short' => t('@field_label updated', array(
'@field_label' => $field_title,
)),
'help' => t('The date the calendar was last updated.') . ' ' . $field_views_info['help'],
'field' => array(
'field_name' => 'changed',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
'element type' => 'span',
),
'argument' => array(
'field' => 'changed',
'field_name' => 'changed',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_argument_date',
),
'filter' => array(
'field' => 'changed',
'field_name' => 'changed',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_filter_date',
'allow empty' => FALSE,
),
'sort' => array(
'field' => 'changed',
'field_name' => 'changed',
'table' => 'availability_calendar_calendar',
'handler' => 'views_handler_sort_date',
),
);
$data['availability_calendar_calendar_' . $field_table_name] = $table_availability_calendar_calendar;
}
}
function availability_calendar_views_plugins() {
return array(
'argument validator' => array(
'availability_calendar_date_range' => array(
'title' => t('Date range for Availability Calendar'),
'handler' => 'availability_calendar_plugin_argument_validate_date_range',
),
),
);
}