else {
$options = CRM_Core_PseudoConstant::get($daoName, $fieldName);
if (is_array($options)) {
- $this->$dbName = $options[0];
+ $this->$dbName = $options[0] ?? NULL;
}
else {
$defaultValues = explode(',', $options);
// Prefer to instantiate BAO's instead of DAO's (when possible)
// so that assignTestValue()/assignTestFK() can be overloaded.
$baoName = str_replace('_DAO_', '_BAO_', $daoName);
- if ($baoName === 'CRM_Financial_BAO_FinancialTrxn') {
- // OMG OMG OMG this is so incredibly bad. The BAO is insanely named.
- // @todo create a new class called what the BAO SHOULD be
- // that extends BAO-crazy-name.... migrate.
- $baoName = 'CRM_Core_BAO_FinancialTrxn';
- }
if (class_exists($baoName)) {
$daoName = $baoName;
}
return static::$_paths ?? [];
}
+ /**
+ * Overridable function to get icon for a particular entity.
+ *
+ * Example: `CRM_Contact_BAO_Contact::getIcon('Contact', 123)`
+ *
+ * @param string $entityName
+ * Short name of the entity. This may seem redundant because the entity name can usually be inferred
+ * from the BAO class being called, but not always. Some virtual entities share a BAO class.
+ * @param int $entityId
+ * Id of the entity.
+ * @throws CRM_Core_Exception
+ */
+ public static function getEntityIcon(string $entityName, int $entityId) {
+ if (static::class === 'CRM_Core_DAO' || static::class !== CRM_Core_DAO_AllCoreTables::getBAOClassName(static::class)) {
+ throw new CRM_Core_Exception('CRM_Core_DAO::getIcon must be called on a BAO class e.g. CRM_Contact_BAO_Contact::getIcon("Contact", 123).');
+ }
+ // By default, just return the icon representing this entity. If there's more complex lookup to do,
+ // the BAO for this entity should override this method.
+ return static::$_icon;
+ }
+
/**
* When creating a record without a supplied name,
* create a unique, clean name derived from the label.
return;
}
$label = $this->label ?? $this->title ?? NULL;
- if (!$label && $label !== '0' && !$isRequired) {
- // No label supplied and name not required, do nothing
+ if (!$label && $label !== '0') {
+ // No label supplied, do nothing
return;
}
$maxLen = static::getSupportedFields()['name']['maxlength'] ?? 255;