$return = [];
foreach (array_keys($this->getBasicTokens()) as $fieldName) {
if ($this->isAddPseudoTokens($fieldName)) {
- $return[$fieldName . ':label'] = $this->fieldMetadata[$fieldName]['input_attrs']['label'];
- $return[$fieldName . ':name'] = ts('Machine name') . ': ' . $this->fieldMetadata[$fieldName]['input_attrs']['label'];
+ $fieldLabel = $this->fieldMetadata[$fieldName]['input_attrs']['label'] ?? $this->fieldMetadata[$fieldName]['label'];
+ $return[$fieldName . ':label'] = $fieldLabel;
+ $return[$fieldName . ':name'] = ts('Machine name') . ': ' . $fieldLabel;
}
}
return $return;
// v4 style custom tokens - but medium term this IF will probably go.
return FALSE;
}
- return (bool) $this->getFieldMetadata()[$fieldName]['options'];
+ return (bool) ($this->getFieldMetadata()[$fieldName]['options'] || !empty($this->getFieldMetadata()[$fieldName]['suffixes']));
}
/**
$field->setLabel($data['html']['label'] ?? NULL);
if (!empty($data['pseudoconstant'])) {
// Do not load options if 'prefetch' is explicitly FALSE
- if ($data['pseudoconstant']['prefetch'] ?? TRUE) {
+ if (!isset($data['pseudoconstant']['prefetch']) || $data['pseudoconstant']['prefetch'] === FALSE) {
$field->setOptionsCallback([__CLASS__, 'getOptions']);
}
// These suffixes are always supported if a field has options
namespace api\v4\Action;
use api\v4\UnitTestCase;
+use Civi\Api4\Campaign;
use Civi\Api4\Contact;
use Civi\Api4\Contribution;
public function testPreloadFalse() {
\CRM_Core_BAO_ConfigSetting::enableComponent('CiviContribute');
\CRM_Core_BAO_ConfigSetting::enableComponent('CiviCampaign');
+ Campaign::create()->setValues(['name' => 'Big Campaign', 'title' => 'Biggie'])->execute();
// The campaign_id field has preload = false in the schema,
// Which means the options will NOT load but suffixes are still available
$fields = Contribution::getFields(FALSE)