You are here

protected function CivicrmEntityViewsData::processViewsDataForSpecialFields in CiviCRM Entity 8.3

Add views integration for fields that require special handling.

Parameters

array $views_field: Array of fields from ::getViewsData().

string $base_table: The base table, most likely the CiviCRM entity type.

1 call to CivicrmEntityViewsData::processViewsDataForSpecialFields()
CivicrmEntityViewsData::getViewsData in src/CivicrmEntityViewsData.php
Returns views data for the entity type.

File

src/CivicrmEntityViewsData.php, line 295

Class

CivicrmEntityViewsData

Namespace

Drupal\civicrm_entity

Code

protected function processViewsDataForSpecialFields(array &$views_field, $base_table) {
  switch ($base_table) {
    case 'civicrm_activity':
      $views_field[$base_table]['source_contact_id']['filter'] = [
        'id' => 'civicrm_entity_civicrm_activity_contact_record',
      ];
      $views_field[$base_table]['assignee_id']['filter'] = [
        'id' => 'civicrm_entity_civicrm_activity_contact_record',
      ];
      $views_field[$base_table]['target_id']['filter'] = [
        'id' => 'civicrm_entity_civicrm_activity_contact_record',
      ];
      $views_field[$base_table]['attachments'] = [
        'title' => $this
          ->t('Attachments'),
        'help' => $this
          ->t('Attachments for the CiviCRM activity.'),
        'field' => [
          'id' => 'civicrm_entity_activity_attachments',
          'field' => 'id',
          'click sortable' => FALSE,
        ],
      ];
      $views_field[$base_table]['activity_end_datetime'] = [
        'title' => $this
          ->t('Activity End Date'),
        'help' => $this
          ->t('The calculated end date and time, for calendar integrations.'),
        'field' => [
          'id' => 'civicrm_entity_activity_end_datetime',
          'field_name' => 'activity_end_datetime',
          'click sortable' => FALSE,
        ],
      ];
      $views_field[$base_table]['contact'] = [
        'title' => $this
          ->t('Contact'),
        'help' => $this
          ->t('Relate CiviCRM contact to CiviCRM activity.'),
        'relationship' => [
          'id' => 'civicrm_entity_activity_contact',
          'base' => 'civicrm_contact',
          'base field' => 'id',
          'first field' => 'activity_id',
          'second field' => 'contact_id',
          'label' => $this
            ->t('Contact'),
        ],
      ];
      $views_field['civicrm_contact']['activity'] = [
        'title' => $this
          ->t('Activity'),
        'help' => $this
          ->t('Relate CiviCRM activity to CiviCRM contact.'),
        'relationship' => [
          'id' => 'civicrm_entity_activity_contact',
          'base' => 'civicrm_activity',
          'base field' => 'id',
          'first field' => 'contact_id',
          'second field' => 'activity_id',
          'label' => $this
            ->t('Activity'),
        ],
      ];
      unset($views_field['civicrm_contact']['reverse__civicrm_activity__assignee_id'], $views_field['civicrm_contact']['reverse__civicrm_activity__target_id'], $views_field['civicrm_contact']['reverse__civicrm_activity__source_contact_id'], $views_field[$base_table]['assignee_id']['relationship'], $views_field[$base_table]['target_id']['relationship'], $views_field[$base_table]['source_contact_id']['relationship']);
      break;
    case 'civicrm_contact':
      $views_field['civicrm_contact']['user'] = [
        'title' => $this
          ->t('User related to the CiviCRM contact'),
        'help' => $this
          ->t('Relate user to the CiviCRM contact.'),
        'relationship' => [
          'base' => 'users_field_data',
          'base field' => 'uid',
          'table' => 'civicrm_uf_match',
          'first field' => 'contact_id',
          'second field' => 'uf_id',
          'id' => 'civicrm_entity_civicrm_contact_user',
          'label' => $this
            ->t('User'),
        ],
      ];
      $views_field['users_field_data']['civicrm_contact'] = [
        'title' => $this
          ->t('CiviCRM contact related to the user'),
        'help' => $this
          ->t('Relate CiviCRM contact to the user.'),
        'relationship' => [
          'base' => 'civicrm_contact',
          'base field' => 'id',
          'table' => 'civicrm_uf_match',
          'first field' => 'uf_id',
          'second field' => 'contact_id',
          'id' => 'civicrm_entity_civicrm_contact_user',
          'label' => $this
            ->t('CiviCRM contact'),
        ],
      ];
      $views_field['civicrm_contact']['civicrm_tag'] = [
        'title' => $this
          ->t('CiviCRM tag related to the CiviCRM contact'),
        'help' => $this
          ->t('Relate CiviCRM tag to the CiviCRM contact.'),
        'relationship' => [
          'base' => 'civicrm_tag',
          'base field' => 'id',
          'table' => 'civicrm_entity_tag',
          'first field' => 'entity_id',
          'second field' => 'tag_id',
          'id' => 'civicrm_entity_civicrm_bridge',
          'label' => $this
            ->t('CiviCRM tag'),
          'extra' => [
            [
              'field' => 'entity_table',
              'value' => 'civicrm_contact',
            ],
          ],
        ],
      ];
      $views_field['civicrm_tag']['civicrm_contact'] = [
        'title' => $this
          ->t('CiviCRM contact related to the CiviCRM tag'),
        'help' => $this
          ->t('Relate CiviCRM contact to the CiviCRM tag.'),
        'relationship' => [
          'base' => 'civicrm_contact',
          'base field' => 'id',
          'table' => 'civicrm_entity_tag',
          'first field' => 'tag_id',
          'second field' => 'entity_id',
          'id' => 'civicrm_entity_civicrm_bridge',
          'label' => $this
            ->t('CiviCRM contact'),
          'extra' => [
            [
              'field' => 'entity_table',
              'value' => 'civicrm_contact',
            ],
          ],
        ],
      ];
      break;
    case 'civicrm_phone':
      if (isset($views_field['civicrm_contact']['reverse__civicrm_phone__contact_id']['relationship'])) {
        $views_field['civicrm_contact']['reverse__civicrm_phone__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_location';
        $views_field['civicrm_contact']['reverse__civicrm_phone__contact_id']['relationship']['label'] = $this
          ->t('Phone');
      }
      break;
    case 'civicrm_address':
      if (isset($views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship'])) {
        $views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_location';
        $views_field['civicrm_contact']['reverse__civicrm_address__contact_id']['relationship']['label'] = $this
          ->t('Address');
      }
      $views_field[$base_table]['proximity'] = [
        'title' => $this
          ->t('Proximity'),
        'help' => $this
          ->t('Search for addresses by proxmity.'),
        'filter' => [
          'id' => 'civicrm_entity_civicrm_address_proximity',
        ],
      ];
      break;
    case 'civicrm_email':
      if (isset($views_field['civicrm_contact']['reverse__civicrm_email__contact_id']['relationship'])) {
        $views_field['civicrm_contact']['reverse__civicrm_email__contact_id']['relationship']['id'] = 'civicrm_entity_reverse_location';
        $views_field['civicrm_contact']['reverse__civicrm_email__contact_id']['relationship']['label'] = $this
          ->t('Email');
      }
      break;
    case 'civicrm_group':
      $views_field['civicrm_group']['civicrm_contact'] = [
        'title' => $this
          ->t('CiviCRM contact related to the CiviCRM group'),
        'help' => $this
          ->t('Relate CiviCRM contact to the CiviCRM group.'),
        'relationship' => [
          'base' => 'civicrm_contact',
          'base field' => 'id',
          'table' => 'civicrm_group_contact',
          'first field' => 'group_id',
          'second field' => 'contact_id',
          'id' => 'civicrm_entity_civicrm_group_contact',
          'label' => $this
            ->t('CiviCRM contact'),
          'extra' => [
            [
              'field' => 'status',
              'value' => 'Added',
            ],
          ],
        ],
      ];
      $views_field['civicrm_contact']['civicrm_group'] = [
        'title' => $this
          ->t('CiviCRM group related to the CiviCRM contact'),
        'help' => $this
          ->t('Relate CiviCRM group to the CiviCRM contact.'),
        'relationship' => [
          'base' => 'civicrm_group',
          'base field' => 'id',
          'table' => 'civicrm_group_contact',
          'first field' => 'contact_id',
          'second field' => 'group_id',
          'id' => 'civicrm_entity_civicrm_group_contact',
          'label' => $this
            ->t('CiviCRM group'),
          'extra' => [
            [
              'field' => 'status',
              'value' => 'Added',
            ],
          ],
        ],
      ];
      break;
    case 'civicrm_case':
      $views_field['civicrm_case']['civicrm_activity'] = [
        'title' => $this
          ->t('CiviCRM activity related to the CiviCRM case'),
        'help' => $this
          ->t('Relate CiviCRM activity to the CiviCRM case.'),
        'relationship' => [
          'base' => 'civicrm_activity',
          'base field' => 'id',
          'table' => 'civicrm_case_activity',
          'first field' => 'case_id',
          'second field' => 'activity_id',
          'id' => 'civicrm_entity_civicrm_case_activity',
          'label' => $this
            ->t('CiviCRM activity'),
        ],
      ];
      $views_field['civicrm_activity']['civicrm_case'] = [
        'title' => $this
          ->t('CiviCRM case related to the CiviCRM activity'),
        'help' => $this
          ->t('Relate CiviCRM case to the CiviCRM activity.'),
        'relationship' => [
          'base' => 'civicrm_case',
          'base field' => 'id',
          'table' => 'civicrm_case_activity',
          'first field' => 'activity_id',
          'second field' => 'case_id',
          'id' => 'civicrm_entity_civicrm_case_activity',
          'label' => $this
            ->t('CiviCRM case'),
        ],
      ];
      $views_field['civicrm_case']['civicrm_contact'] = [
        'title' => $this
          ->t('CiviCRM contact related to the CiviCRM case'),
        'help' => $this
          ->t('Relate CiviCRM contact to the CiviCRM case.'),
        'relationship' => [
          'base' => 'civicrm_contact',
          'base field' => 'id',
          'table' => 'civicrm_case_contact',
          'first field' => 'case_id',
          'second field' => 'contact_id',
          'id' => 'civicrm_entity_civicrm_case_contact',
          'label' => $this
            ->t('CiviCRM contact'),
        ],
      ];
      $views_field['civicrm_contact']['civicrm_case'] = [
        'title' => $this
          ->t('CiviCRM case related to the CiviCRM contact'),
        'help' => $this
          ->t('Relate CiviCRM case to the CiviCRM contact.'),
        'relationship' => [
          'base' => 'civicrm_case',
          'base field' => 'id',
          'table' => 'civicrm_case_contact',
          'first field' => 'contact_id',
          'second field' => 'case_id',
          'id' => 'civicrm_entity_civicrm_case_contact',
          'label' => $this
            ->t('CiviCRM case'),
        ],
      ];
      unset($views_field['civicrm_case']['medium_id']);
      unset($views_field['civicrm_case']['contact_id']['relationship']);
      break;
    case 'civicrm_line_item':
      $views_field['civicrm_line_item']['entity_id'] = [
        'title' => $this
          ->t('CiviCRM membership'),
        'help' => $this
          ->t('Relate CiviCRM entity to the line item entity for membership.'),
        'relationship' => [
          'id' => 'standard',
          'base field' => 'id',
          'base' => 'civicrm_membership',
          'label' => $this
            ->t('Membership'),
        ],
      ];
      break;
    case 'civicrm_price_set':
      $views_field['civicrm_price_set_entity']['table'] = [
        'group' => $this
          ->t('CiviCRM price set entity'),
        'base' => [
          'field' => 'id',
          'title' => $this
            ->t('CiviCRM price set entity'),
          'help' => $this
            ->t('View displays CiviCRM Price Set to Entity mapping info.'),
        ],
      ];
      $views_field['civicrm_price_set_entity']['price_set_id'] = [
        'title' => $this
          ->t('Price set'),
        'help' => $this
          ->t('Price set for this entity.'),
        'relationship' => [
          'id' => 'standard',
          'base' => 'civicrm_price_set',
          'base field' => 'id',
          'label' => $this
            ->t('Price set'),
        ],
      ];
      $views_field['civicrm_event']['table']['join']['civicrm_price_set_entity'] = [
        'left_field' => 'entity_id',
        'field' => 'id',
      ];
      $views_field['civicrm_price_set_entity']['table']['join']['civicrm_event'] = [
        'left_field' => 'id',
        'field' => 'entity_id',
      ];
  }
}