<?php

/**
 * @file
 * The Social activity filter module.
 */

/**
 * Implements hook_views_plugins_display_alter().
 */
function social_activity_filter_views_plugins_display_alter(array &$plugins) {
  $plugins['block']['class'] = 'Drupal\social_activity_filter\Plugin\views\display\FilterBlock';
}

/**
 * Implements hook_views_data().
 */
function social_activity_filter_views_data() {
  $data['activity']['activity_filter_tags'] = [
    'title' => t('Filter activities by tags'),
    'filter' => [
      'title' => t('Filter activities by tags'),
      'help' => t('Filter activities by tags'),
      'field' => 'tags',
      'id' => 'activity_filter_tags',
    ],
  ];
  return $data;
}

/**
 * Gets default activity views list for filtering.
 */
function social_activity_default_views_list() {
  $default_views_list = [
    'community_activities',
    'activity_stream',
  ];

  \Drupal::moduleHandler()
    ->alter('social_activity_default_views_list', $default_views_list);

  return $default_views_list;
}

/**
 * Gets tags filter views data.
 */
function social_activity_get_tag_filter_data() {
  return [
    'id' => 'activity_filter_tags',
    'table' => 'activity',
    'field' => 'activity_filter_tags',
    'relationship' => 'none',
    'group_type' => 'group',
    'admin_label' => '',
    'operator' => '=',
    'value' => '',
    'group' => 1,
    'exposed' => FALSE,
    'expose' => [
      'operator_id' => '',
      'label' => '',
      'description' => '',
      'use_operator' => FALSE,
      'operator' => '',
      'operator_limit_selection' => FALSE,
      'operator_list' => [],
      'identifier' => '',
      'required' => FALSE,
      'remember' => FALSE,
      'multiple' => FALSE,
      'remember_roles' => [
        'authenticated' => 'authenticated',
      ],
    ],
    'is_grouped' => FALSE,
    'group_info' => [
      'label' => '',
      'description' => '',
      'identifier' => '',
      'optional' => TRUE,
      'widget' => 'select',
      'multiple' => FALSE,
      'remember' => FALSE,
      'default_group' => 'All',
      'default_group_multiple' => [],
      'group_items' => [],
    ],
    'entity_type' => 'activity',
    'plugin_id' => 'activity_filter_tags',
  ];
}
