+--------------------------------------------------------------------+
*/
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-
-
namespace Civi\Api4\Generic;
+use Civi\Api4\Utils\CoreUtil;
+use Civi\Api4\Utils\FormattingUtil;
+
/**
* @inheritDoc
* @method bool getIncludeCustom()
// Any fields name with a dot in it is either custom or an implicit join
$includeCustom = strpos(implode('', $fieldsToGet), '.') !== FALSE;
}
+ $this->formatValues();
$spec = $gatherer->getSpec($this->getEntityName(), $this->getAction(), $includeCustom, $this->values);
$fields = $this->specToArray($spec->getFields($fieldsToGet));
foreach ($fieldsToGet ?? [] as $fieldName) {
}
}
+ /**
+ * Special handling for pseudoconstant replacements.
+ *
+ * Normally this would involve calling getFields... but this IS getFields.
+ *
+ * @throws \API_Exception
+ */
+ private function formatValues() {
+ foreach (array_keys($this->values) as $key) {
+ if (strpos($key, ':')) {
+ [$fieldName, $suffix] = explode(':', $key);
+ $context = FormattingUtil::$pseudoConstantContexts[$suffix] ?? NULL;
+ if (!$context) {
+ throw new \API_Exception('Illegal expression');
+ }
+ $baoName = CoreUtil::getBAOFromApiName($this->getEntityName());
+ $options = $baoName::buildOptions($fieldName, $context);
+ $this->values[$fieldName] = FormattingUtil::replacePseudoconstant($options, $this->values[$key], TRUE);
+ unset($this->values[$key]);
+ }
+ }
+ }
+
public function fields() {
$fields = parent::fields();
$fields[] = [
'data_type' => 'Array',
'@internal' => TRUE,
];
+ $fields[] = [
+ 'name' => 'sql_renderer',
+ 'data_type' => 'Array',
+ '@internal' => TRUE,
+ ];
return $fields;
}