$multiField = uniqid('chkbx');
$textField = uniqid('txt');
- $customGroup = CustomGroup::create()
- ->setCheckPermissions(FALSE)
+ $customGroup = CustomGroup::create(FALSE)
->addValue('name', $group)
->addValue('extends', 'Contact')
->addValue('is_multiple', TRUE)
->execute()
->first();
- CustomField::create()
- ->setCheckPermissions(FALSE)
+ CustomField::create(FALSE)
->addValue('label', $colorField)
- ->addValue('options', $optionValues)
+ ->addValue('option_values', $optionValues)
->addValue('custom_group_id', $customGroup['id'])
->addValue('html_type', 'Select')
->addValue('data_type', 'String')
->execute();
- CustomField::create()
- ->setCheckPermissions(FALSE)
+ CustomField::create(FALSE)
->addValue('label', $multiField)
- ->addValue('options', $optionValues)
+ ->addValue('option_values', $optionValues)
->addValue('custom_group_id', $customGroup['id'])
->addValue('html_type', 'CheckBox')
->addValue('data_type', 'String')
->execute();
- CustomField::create()
- ->setCheckPermissions(FALSE)
+ CustomField::create(FALSE)
->addValue('label', $textField)
->addValue('custom_group_id', $customGroup['id'])
->addValue('html_type', 'Text')
->addValue('data_type', 'String')
->execute();
- $this->contactID = Contact::create()
- ->setCheckPermissions(FALSE)
+ $this->contactID = Contact::create(FALSE)
->addValue('first_name', 'Johann')
->addValue('last_name', 'Tester')
->addValue('contact_type', 'Individual')
->first()['id'];
// Retrieve and check the fields of CustomValue = Custom_$group
- $fields = CustomValue::getFields($group)->execute();
+ $fields = CustomValue::getFields($group)->setLoadOptions(TRUE)->setCheckPermissions(FALSE)->execute();
$expectedResult = [
[
'custom_group' => $group,
'data_type' => 'String',
'fk_entity' => NULL,
'serialize' => NULL,
+ 'options' => $optionValues,
],
[
'custom_group' => $group,
'data_type' => 'String',
'fk_entity' => NULL,
'serialize' => 1,
+ 'options' => $optionValues,
],
[
'custom_group' => $group,
->execute();
// fetch custom values using API4 CustomValue::get
$result = CustomValue::get($group)
+ ->addSelect('id', 'entity_id', $colorField, $colorField . ':label')
->addOrderBy($colorField, 'DESC')
->execute();
[
'id' => 2,
$colorField => 'r',
+ $colorField . ':label' => 'Red',
'entity_id' => $this->contactID,
],
[
'id' => 1,
$colorField => 'g',
+ $colorField . ':label' => 'Green',
'entity_id' => $this->contactID,
],
];
// Update a records whose id is 1 and change the custom field (name = Color) value to 'Blue' from 'Green'
CustomValue::update($group)
->addWhere("id", "=", 1)
- ->addValue($colorField, 'b')
+ ->addValue($colorField . ':label', 'Blue')
->execute();
// ensure that the value is changed for id = 1
// CASE 3: Test CustomValue::replace
// create a second contact which will be used to replace the custom values, created earlier
- $secondContactID = Contact::create()
- ->setCheckPermissions(FALSE)
+ $secondContactID = Contact::create(FALSE)
->addValue('first_name', 'Adam')
->addValue('last_name', 'Tester')
->addValue('contact_type', 'Individual')
// Replace all the records which was created earlier with entity_id = first contact
// with custom record [$colorField => 'g', 'entity_id' => $secondContactID]
CustomValue::replace($group)
- ->setRecords([[$colorField => 'g', $multiField => ['r', 'g'], 'entity_id' => $secondContactID]])
+ ->setRecords([[$colorField => 'g', $multiField . ':label' => ['Red', 'Green'], 'entity_id' => $secondContactID]])
->addWhere('entity_id', '=', $this->contactID)
->execute();
// Check the two records created earlier is replaced by new contact
- $result = CustomValue::get($group)->execute();
+ $result = CustomValue::get($group)
+ ->addSelect('id', 'entity_id', $colorField, $colorField . ':label', $multiField, $multiField . ':label')
+ ->execute();
$this->assertEquals(1, count($result));
$expectedResult = [
[
'id' => 3,
$colorField => 'g',
+ $colorField . ':label' => 'Green',
$multiField => ['r', 'g'],
+ $multiField . ':label' => ['Red', 'Green'],
'entity_id' => $secondContactID,
],
];