/** * Clean and validate the filter before it is used in a db query. * * @param string $entityType * @param string $subType * * @return string * @throws \CRM_Core_Exception * @throws \CiviCRM_API3_Exception */ protected static function validateSubTypeByEntity($entityType, $subType) { $subType = trim($subType, CRM_Core_DAO::VALUE_SEPARATOR); if (is_numeric($subType)) { return $subType; } $contactTypes = CRM_Contact_BAO_ContactType::basicTypeInfo(TRUE); if ($entityType != 'Contact' && !array_key_exists($entityType, $contactTypes)) { throw new CRM_Core_Exception('Invalid Entity Filter'); } $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo($entityType, TRUE); if (!array_key_exists($subType, $subTypes)) { throw new CRM_Core_Exception('Invalid Filter'); } return $subType; }