You are here

protected function CivicrmEntityViewsData::getViewsFilterPlugin in CiviCRM Entity 8.3

Get the views sort handler.

Parameters

array $field_metadata: An array of field metadata.

Return value

array An array containing the corresponding values for the 'filter' key.

1 call to CivicrmEntityViewsData::getViewsFilterPlugin()
CivicrmEntityViewsData::processViewsDataForCustomFields in src/CivicrmEntityViewsData.php
Add views integration for custom fields.

File

src/CivicrmEntityViewsData.php, line 654

Class

CivicrmEntityViewsData

Namespace

Drupal\civicrm_entity

Code

protected function getViewsFilterPlugin(array $field_metadata) {
  switch ($field_metadata['data_type']) {
    case 'Country':
      $filter = [
        'id' => 'civicrm_entity_in_operator',
        'options callback' => 'CRM_Core_PseudoConstant::country',
      ];
      if ($field_metadata['html_type'] === 'Multi-Select Country') {
        $filter['multi'] = TRUE;
      }
      return $filter;
    case 'StateProvince':
      $filter = [
        'id' => 'civicrm_entity_in_operator',
        'options callback' => 'CRM_Core_PseudoConstant::stateProvince',
      ];
      if ($field_metadata['html_type'] === 'Multi-Select State/Province') {
        $filter['multi'] = TRUE;
      }
      return $filter;
    case 'ContactReference':
      return [
        'id' => 'civicrm_entity_contact_reference',
      ];
  }
  $type = !empty($field_metadata['pseudoconstant']) ? 'pseudoconstant' : \CRM_Utils_Array::value($field_metadata['data_type'], \CRM_Core_BAO_CustomField::dataToType());
  switch ($type) {
    case \CRM_Utils_Type::T_BOOLEAN:
      return [
        'id' => 'boolean',
        'accept_null' => TRUE,
      ];
    case \CRM_Utils_Type::T_INT:
    case \CRM_Utils_Type::T_FLOAT:
    case \CRM_Utils_Type::T_MONEY:
      return [
        'id' => 'numeric',
      ];
    case \CRM_Utils_Type::T_ENUM:
    case \CRM_Utils_Type::T_STRING:
    case \CRM_Utils_Type::T_TEXT:
    case \CRM_Utils_Type::T_LONGTEXT:
    case \CRM_Utils_Type::T_URL:
    case \CRM_Utils_Type::T_EMAIL:
      return [
        'id' => 'string',
      ];
    case \CRM_Utils_Type::T_DATE:
    case \CRM_Utils_Type::T_TIMESTAMP:
      return [
        'id' => 'civicrm_entity_date',
      ];
    case 'pseudoconstant':
      if ($class_name = SupportedEntities::getEntityTypeDaoClass($field_metadata['entity_type'])) {
        $filter = [
          'id' => 'civicrm_entity_in_operator',
          'options callback' => "{$class_name}::buildOptions",
          'options arguments' => $field_metadata['name'],
        ];
        if (in_array($field_metadata['html_type'], [
          'Multi-Select',
          'CheckBox',
        ])) {
          $filter['multi'] = TRUE;
        }
        return $filter;
      }
      break;
    default:
      return [
        'id' => 'standard',
      ];
  }
}