if (array_key_exists('label', $fieldDefaults)) {
$field['label'] = $field['label'] ?? $field['title'] ?? $field['name'];
}
- if (!empty($field['options']) && is_array($field['options']) && empty($field['suffixes']) && array_key_exists('suffixes', $field)) {
+ if (isset($field['options']) && is_array($field['options']) && empty($field['suffixes']) && array_key_exists('suffixes', $field)) {
$this->setFieldSuffixes($field);
}
if (isset($defaults['options'])) {
* @param array $field
*/
private function formatOptionList(&$field) {
- if (empty($field['options'])) {
+ $optionsExist = isset($field['options']) && is_array($field['options']);
+ if (!isset($field['options'])) {
$field['options'] = !empty($field['pseudoconstant']);
}
if (!empty($field['pseudoconstant']['optionGroupName'])) {
$field['suffixes'] = CoreUtil::getOptionValueFields($field['pseudoconstant']['optionGroupName']);
}
- if (!$this->loadOptions || !$field['options']) {
+ if (!$this->loadOptions || (!$optionsExist && empty($field['pseudoconstant']))) {
$field['options'] = (bool) $field['options'];
return;
}
$value = array_unique(array_merge($value, $tagTree[$tagID]));
}
}
- $tags = \CRM_Utils_Type::validate(implode(',', $value), 'CommaSeparatedIntegers');
+ $tags = $value ? \CRM_Utils_Type::validate(implode(',', $value), 'CommaSeparatedIntegers') : '0';
return "$fieldAlias $operator (SELECT entity_id FROM `civicrm_entity_tag` WHERE entity_table = '$tableName' AND tag_id IN ($tags))";
}
$bao = CoreUtil::getBAOFromApiName($spec->getEntity());
$optionLabels = $bao::buildOptions($fieldName, NULL, $values);
- if (!is_array($optionLabels) || !$optionLabels) {
+ if (!is_array($optionLabels)) {
$options = FALSE;
}
else {
use Civi\Api4\Email;
use Civi\Api4\EntityTag;
use Civi\Api4\OptionValue;
+use Civi\Api4\Tag;
use Civi\Api4\UserJob;
use Civi\Api4\Utils\CoreUtil;
use Civi\Test\TransactionalInterface;
$this->assertContains('SavedSearch', $tagFields['entity_id']['dfk_entities']);
}
+ public function testEmptyOptionListIsReturnedAsAnArray(): void {
+ Tag::delete(FALSE)
+ ->addWhere('used_for', '=', 'civicrm_activity')
+ ->execute();
+ $field = EntityTag::getFields(FALSE)
+ ->addValue('entity_table', 'civicrm_activity')
+ ->addWhere('name', '=', 'tag_id')
+ ->setLoadOptions(TRUE)
+ ->execute()->single();
+ // There are no tags for Activity but it should still be returned as an array
+ $this->assertIsArray($field['options']);
+ $this->assertEmpty($field['options']);
+ }
+
public function testFiltersAreReturned(): void {
$field = Contact::getFields(FALSE)
->addWhere('name', '=', 'employer_id')
->addWhere('name', '=', 'extends_entity_column_id')
->addValue('extends', 'Contact')
->execute()->first();
- $this->assertFalse($fieldFilteredByContact['options']);
+ $this->assertEquals([], $fieldFilteredByContact['options']);
}
public function testExtendsMetadata(): void {