You are here

function calendar_field_views_data_alter in Calendar 8

Same name and namespace in other branches
  1. 8.2 calendar.views.inc \calendar_field_views_data_alter()

Implements hook_field_views_data_alter().

File

./calendar.views.inc, line 66
Provides views data for the calendar module.

Code

function calendar_field_views_data_alter(array &$data, FieldStorageConfigInterface $field_storage) {
  foreach ($data as $table_name => $table_data) {

    // Set the 'datetime' filter type.
    if (isset($data[$table_name][$field_storage
      ->getName() . '_value']) && $data[$table_name][$field_storage
      ->getName() . '_value']['filter']['id'] == 'datetime') {

      // Create year, month, and day arguments.
      $group = $data[$table_name][$field_storage
        ->getName() . '_value']['group'];
      $arguments = [
        // Argument type => help text.
        'year_week' => t('Calendar Date in the form of CCYYW.'),
      ];
      foreach ($arguments as $argument_type => $help_text) {
        $data[$table_name][$field_storage
          ->getName() . '_value_' . $argument_type] = [
          'title' => 'Calendar ' . $field_storage
            ->getLabel() . ' (' . $argument_type . ')',
          'help' => $help_text,
          'argument' => [
            'field' => $field_storage
              ->getName() . '_value',
            'id' => 'datetime_' . $argument_type,
            'entity_type' => $field_storage
              ->getTargetEntityTypeId(),
            'field_name' => $field_storage
              ->getName(),
          ],
          'group' => $group,
        ];
      }
    }
  }
}