You are here

function availability_calendar_views_data_alter in Availability Calendars 7.5

Implements hook_views_data_alter().

We change the filter and argument handlers for indexed fields from the type "Availability". Fields that are declared to be of this type should either be the cid field of an availability calendar field (field type = integer) or the filtered availability property of an availability calendar entity (field type = list<date>).

Parameters

array $data:

See also

hook_views_data()

File

views/availability_calendar.views.inc, line 171
Views support for Availability Calendar.

Code

function availability_calendar_views_data_alter(&$data) {
  if (module_exists('search_api')) {
    $indices = search_api_index_load_multiple(FALSE);
    foreach ($indices as $index) {
      foreach (availability_calendar_get_search_api_index_availability_fields($index->id) as $search_field_name => $search_field) {
        $views_field_name = str_replace(":", "_", $search_field_name);
        $views_field =& $data['search_api_index_' . $index->machine_name][$views_field_name];

        // Change the filter handler.
        $views_field['filter']['handler'] = 'availability_calendar_handler_filter_indexed_availability';
        $views_field['filter']['allocation_type'] = availability_calendar_get_allocation_type($search_field_name);

        // Pass on additional information. cid fields will be joined to a table
        // with filtered availability in another index (should be created
        // separately). For filtered availability fields, the table itself will
        // be used.
        $views_field['filter']['filtered_availability_table'] = search_api_extract_inner_type($views_field['field']['type']) === 'date' ? availability_calendar_get_search_api_availability_index_table($index->server) : '';

        // And change the argument handler accordingly.
        $views_field['argument']['handler'] = 'availability_calendar_handler_argument_indexed_availability';
        $views_field['argument']['filtered_availability_table'] = $views_field['filter']['filtered_availability_table'];
        $views_field['argument']['allocation_type'] = $views_field['filter']['allocation_type'];
      }
    }
  }
}