This function was overly strict about not accepting BAO names, prompting end-users of the function
to do their own ad-hoc conversions before using it.
if (!$blockCopyofCustomValues) {
$newObject->copyCustomFields($object->id, $newObject->id);
}
- CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName(str_replace('_BAO_', '_DAO_', $daoName)), $newObject->id, $newObject);
+ CRM_Utils_Hook::post('create', CRM_Core_DAO_AllCoreTables::getBriefName($daoName), $newObject->id, $newObject);
}
return $newObject;
* Ex: 'Contact'.
*/
public static function getBriefName($className) {
- return CRM_Utils_Array::value($className, array_flip(self::daoToClass()));
+ $className = self::getCanonicalClassName($className);
+ return array_search($className, self::daoToClass(), TRUE) ?: NULL;
}
/**
'fresh' => FALSE,
'context' => $context,
];
- $entity = CRM_Core_DAO_AllCoreTables::getBriefName(CRM_Core_DAO_AllCoreTables::getCanonicalClassName($daoName));
+ $entity = CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
// Custom fields are not in the schema
if (strpos($fieldName, 'custom_') === 0 && is_numeric($fieldName[7])) {
/**
* Having a DAO object find the entity name.
*
- * @param object $bao
+ * @param CRM_Core_DAO $bao
* DAO being passed in.
*
* @return string
*/
function _civicrm_api_get_entity_name_from_dao($bao) {
- $daoName = str_replace("BAO", "DAO", get_class($bao));
- return CRM_Core_DAO_AllCoreTables::getBriefName($daoName);
+ return CRM_Core_DAO_AllCoreTables::getBriefName(get_class($bao));
}
* @return array
*/
function _civicrm_api3_basic_get($bao_name, $params, $returnAsSuccess = TRUE, $entity = "", $sql = NULL, $uniqueFields = FALSE) {
- $entity = $entity ?: CRM_Core_DAO_AllCoreTables::getBriefName(str_replace('_BAO_', '_DAO_', $bao_name));
+ $entity = $entity ?: CRM_Core_DAO_AllCoreTables::getBriefName($bao_name);
$options = _civicrm_api3_get_options_from_params($params);
$query = new \Civi\API\Api3SelectQuery($entity, CRM_Utils_Array::value('check_permissions', $params, FALSE));
$this->assertFalse(CRM_Core_DAO_AllCoreTables::isCoreTable('civicrm_invalid_table'), 'civicrm_invalid_table should NOT be a core table');
}
+ public function testGetBriefName() {
+ $this->assertEquals('Contact', CRM_Core_DAO_AllCoreTables::getBriefName('CRM_Contact_BAO_Contact'));
+ $this->assertEquals('Contact', CRM_Core_DAO_AllCoreTables::getBriefName('CRM_Contact_DAO_Contact'));
+ }
+
}