namespace Civi\Api4\Action\Address;
/**
- * @inheritDoc
+ * Code shared by Address create/update/save actions
+ *
* @method bool getStreetParsing()
* @method $this setStreetParsing(bool $streetParsing)
* @method bool getSkipGeocode()
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\Contact;
+
+/**
+ * Code shared by Contact create/update/save actions
+ */
+trait ContactSaveTrait {
+
+ /**
+ * @param array $items
+ * @return array
+ */
+ protected function write(array $items) {
+ foreach ($items as &$contact) {
+ // For some reason the contact BAO requires this for updates
+ if (!empty($contact['id'])) {
+ $contact['contact_id'] = $contact['id'];
+ }
+ elseif (empty($contact['contact_type'])) {
+ // Guess which type of contact is being created
+ if (!empty($contact['organization_name'])) {
+ $contact['contact_type'] = 'Organization';
+ }
+ elseif (!empty($contact['household_name'])) {
+ $contact['contact_type'] = 'Household';
+ }
+ else {
+ $contact['contact_type'] = 'Individual';
+ }
+ }
+ }
+ return parent::write($items);
+ }
+
+}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\Contact;
+
+/**
+ * @inheritDoc
+ */
+class Create extends \Civi\Api4\Generic\DAOCreateAction {
+ use ContactSaveTrait;
+
+}
* @inheritDoc
*/
class Save extends \Civi\Api4\Generic\DAOSaveAction {
-
- /**
- * @param array $items
- * @return array
- */
- protected function write(array $items) {
- $saved = [];
- foreach ($items as $item) {
- // For some reason the contact BAO requires this for updates
- if (!empty($item['id']) && !\CRM_Utils_System::isNull($item['id'])) {
- $item['contact_id'] = $item['id'];
- }
- $saved[] = \CRM_Contact_BAO_Contact::create($item);
- }
- return $saved;
- }
+ use ContactSaveTrait;
}
* @inheritDoc
*/
class Update extends \Civi\Api4\Generic\DAOUpdateAction {
-
- /**
- * @param array $items
- * @return array
- */
- protected function write(array $items) {
- $saved = [];
- foreach ($items as $item) {
- // For some reason the contact BAO requires this for updates
- $item['contact_id'] = $item['id'];
- $saved[] = \CRM_Contact_BAO_Contact::create($item);
- }
- return $saved;
- }
+ use ContactSaveTrait;
}
+--------------------------------------------------------------------+
*/
-namespace Civi\Api4\Event\Subscriber;
+namespace Civi\Api4\Action\Contribution;
-use Civi\Api4\Generic\AbstractAction;
-
-class ContributionPreSaveSubscriber extends Generic\PreSaveSubscriber {
-
- public function modify(&$record, AbstractAction $request) {
- // Required by Contribution BAO
- $record['skipCleanMoney'] = TRUE;
- }
+/**
+ * Code shared by Contribution create/update/save actions
+ */
+trait ContributionSaveTrait {
- public function applies(AbstractAction $request) {
- return $request->getEntityName() === 'Contribution';
+ /**
+ * @inheritDoc
+ */
+ protected function write(array $items) {
+ foreach ($items as &$item) {
+ // Required by Contribution BAO
+ $item['skipCleanMoney'] = TRUE;
+ }
+ return parent::write($items);
}
}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\Contribution;
+
+/**
+ * @inheritDoc
+ */
+class Create extends \Civi\Api4\Generic\DAOCreateAction {
+ use ContributionSaveTrait;
+
+}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\Contribution;
+
+/**
+ * @inheritDoc
+ */
+class Save extends \Civi\Api4\Generic\DAOSaveAction {
+ use ContributionSaveTrait;
+
+}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\Contribution;
+
+/**
+ * @inheritDoc
+ */
+class Update extends \Civi\Api4\Generic\DAOUpdateAction {
+ use ContributionSaveTrait;
+
+}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\CustomField;
+
+/**
+ * @inheritDoc
+ */
+class Create extends \Civi\Api4\Generic\DAOCreateAction {
+ use CustomFieldSaveTrait;
+
+}
+--------------------------------------------------------------------+
*/
-namespace Civi\Api4\Event\Subscriber;
+namespace Civi\Api4\Action\CustomField;
-use Civi\Api4\Generic\AbstractAction;
-
-class CustomFieldPreSaveSubscriber extends Generic\PreSaveSubscriber {
+/**
+ * Code shared by CustomField create/update/save actions
+ */
+trait CustomFieldSaveTrait {
/**
- * @var string
+ * @inheritDoc
*/
- public $supportedOperation = 'create';
+ protected function write(array $items) {
+ foreach ($items as &$field) {
+ if (empty($field['id'])) {
+ self::formatOptionValues($field);
+ }
+ }
+ return parent::write($items);
+ }
- public function modify(&$field, AbstractAction $request) {
+ /**
+ * If 'option_values' have been supplied, reformat it according to the expectations of the BAO
+ *
+ * @param array $field
+ */
+ private static function formatOptionValues(array &$field): void {
+ $field['option_type'] = !empty($field['option_values']);
if (!empty($field['option_values'])) {
- $weight = $key = 0;
- $field['option_label'] = $field['option_value'] = $field['option_status'] = $field['option_weight'] = [];
+ $weight = 0;
+ $field['option_label'] = $field['option_value'] = $field['option_status'] = $field['option_weight'] =
$field['option_name'] = $field['option_color'] = $field['option_description'] = $field['option_icon'] = [];
foreach ($field['option_values'] as $key => $value) {
// Translate simple key/value pairs into full-blown option values
'id' => $key,
];
}
- $weight++;
$field['option_label'][] = $value['label'] ?? $value['name'];
$field['option_name'][] = $value['name'] ?? NULL;
$field['option_value'][] = $value['id'];
$field['option_status'][] = $value['is_active'] ?? 1;
- $field['option_weight'][] = $value['weight'] ?? $weight;
+ $field['option_weight'][] = $value['weight'] ?? ++$weight;
$field['option_color'][] = $value['color'] ?? NULL;
$field['option_description'][] = $value['description'] ?? NULL;
$field['option_icon'][] = $value['icon'] ?? NULL;
}
}
- $field['option_type'] = !empty($field['option_values']);
- }
-
- public function applies(AbstractAction $request) {
- return $request->getEntityName() === 'CustomField';
}
}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\CustomField;
+
+/**
+ * @inheritDoc
+ */
+class Save extends \Civi\Api4\Generic\DAOSaveAction {
+ use CustomFieldSaveTrait;
+
+}
--- /dev/null
+<?php
+
+/*
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC. All rights reserved. |
+ | |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+ */
+
+namespace Civi\Api4\Action\CustomField;
+
+/**
+ * @inheritDoc
+ */
+class Update extends \Civi\Api4\Generic\DAOUpdateAction {
+ use CustomFieldSaveTrait;
+
+}
*/
class Contact extends Generic\DAOEntity {
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Contact\Create
+ */
+ public static function create($checkPermissions = TRUE) {
+ return (new Action\Contact\Create(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
/**
* @param bool $checkPermissions
* @return Action\Contact\Update
*/
class Contribution extends Generic\DAOEntity {
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Contribution\Create
+ */
+ public static function create($checkPermissions = TRUE) {
+ return (new Action\Contribution\Create(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Contribution\Save
+ */
+ public static function save($checkPermissions = TRUE) {
+ return (new Action\Contribution\Save(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
+ /**
+ * @param bool $checkPermissions
+ * @return Action\Contribution\Update
+ */
+ public static function update($checkPermissions = TRUE) {
+ return (new Action\Contribution\Update(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
}
use Generic\Traits\ManagedEntity;
use Generic\Traits\SortableEntity;
+ /**
+ * @param bool $checkPermissions
+ * @return Action\CustomField\Create
+ */
+ public static function create($checkPermissions = TRUE) {
+ return (new Action\CustomField\Create(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
+ /**
+ * @param bool $checkPermissions
+ * @return Action\CustomField\Save
+ */
+ public static function save($checkPermissions = TRUE) {
+ return (new Action\CustomField\Save(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
+ /**
+ * @param bool $checkPermissions
+ * @return Action\CustomField\Update
+ */
+ public static function update($checkPermissions = TRUE) {
+ return (new Action\CustomField\Update(__CLASS__, __FUNCTION__))
+ ->setCheckPermissions($checkPermissions);
+ }
+
}
+++ /dev/null
-<?php
-
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved. |
- | |
- | This work is published under the GNU AGPLv3 license with some |
- | permitted exceptions and without any warranty. For full license |
- | and copyright information, see https://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
-namespace Civi\Api4\Event\Subscriber;
-
-use Civi\Api4\Generic\AbstractAction;
-
-class ContactPreSaveSubscriber extends Generic\PreSaveSubscriber {
-
- /**
- * @var string
- */
- public $supportedOperation = 'create';
-
- public function modify(&$contact, AbstractAction $request) {
- // Guess which type of contact is being created
- if (empty($contact['contact_type']) && !empty($contact['organization_name'])) {
- $contact['contact_type'] = 'Organization';
- }
- if (empty($contact['contact_type']) && !empty($contact['household_name'])) {
- $contact['contact_type'] = 'Household';
- }
- }
-
- public function applies(AbstractAction $request) {
- return $request->getEntityName() === 'Contact';
- }
-
-}
+++ /dev/null
-<?php
-
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved. |
- | |
- | This work is published under the GNU AGPLv3 license with some |
- | permitted exceptions and without any warranty. For full license |
- | and copyright information, see https://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
-namespace Civi\Api4\Event\Subscriber;
-
-use Civi\Api4\Generic\DAOCreateAction;
-
-class CustomGroupPreCreationSubscriber extends Generic\PreCreationSubscriber {
-
- /**
- * @param \Civi\Api4\Generic\DAOCreateAction $request
- */
- protected function modify(DAOCreateAction $request) {
- $title = $request->getValue('title');
- $name = $request->getValue('name');
-
- if (NULL === $title && $name) {
- $request->addValue('title', $name);
- }
- }
-
- protected function applies(DAOCreateAction $request) {
- return $request->getEntityName() === 'CustomGroup';
- }
-
-}
use Civi\Api4\Generic\AbstractCreateAction;
use Civi\Api4\Generic\AbstractUpdateAction;
+/**
+ * @deprecated
+ */
abstract class PreSaveSubscriber extends AbstractPrepareSubscriber {
/**
$apiRequest = $event->getApiRequest();
if ($apiRequest instanceof AbstractAction && $this->applies($apiRequest)) {
+ \CRM_Core_Error::deprecatedWarning("Use of APIv4 'PreSaveSubscriber' is deprecated. '" . get_class($this) . "' should be removed ({$apiRequest->getEntityName()}::{$apiRequest->getActionName()}).");
if (
($apiRequest instanceof AbstractCreateAction && $this->supportedOperation !== 'update') ||
($apiRequest instanceof AbstractUpdateAction && $this->supportedOperation !== 'create')
+++ /dev/null
-<?php
-
-/*
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC. All rights reserved. |
- | |
- | This work is published under the GNU AGPLv3 license with some |
- | permitted exceptions and without any warranty. For full license |
- | and copyright information, see https://civicrm.org/licensing |
- +--------------------------------------------------------------------+
- */
-
-namespace Civi\Api4\Event\Subscriber;
-
-use Civi\Api4\Generic\DAOCreateAction;
-use Civi\Api4\OptionGroup;
-
-class OptionValuePreCreationSubscriber extends Generic\PreCreationSubscriber {
-
- /**
- * @param \Civi\Api4\Generic\DAOCreateAction $request
- */
- protected function modify(DAOCreateAction $request) {
- $this->setOptionGroupId($request);
- }
-
- /**
- * @param \Civi\Api4\Generic\DAOCreateAction $request
- *
- * @return bool
- */
- protected function applies(DAOCreateAction $request) {
- return $request->getEntityName() === 'OptionValue';
- }
-
- /**
- * @param \Civi\Api4\Generic\DAOCreateAction $request
- * @throws \API_Exception
- * @throws \Exception
- */
- private function setOptionGroupId(DAOCreateAction $request) {
- $optionGroupName = $request->getValue('option_group');
- if (!$optionGroupName || $request->getValue('option_group_id')) {
- return;
- }
- \CRM_Core_Error::deprecatedFunctionWarning('Use option_group_id:name instead of option_group in APIv4');
- $optionGroup = OptionGroup::get(FALSE)
- ->addSelect('id')
- ->addWhere('name', '=', $optionGroupName)
- ->execute();
-
- if ($optionGroup->count() !== 1) {
- throw new \Exception('Option group name must match only a single group');
- }
-
- $request->addValue('option_group_id', $optionGroup->first()['id']);
- }
-
-}
* @param \Civi\Api4\Service\Spec\RequestSpec $spec
*/
public function modifySpec(RequestSpec $spec) {
- $contactTypeField = $spec->getFieldByName('contact_type');
- if ($contactTypeField) {
- $contactTypeField->setDefaultValue('Individual');
- }
-
$spec->getFieldByName('is_opt_out')->setRequired(FALSE);
$spec->getFieldByName('is_deleted')->setRequired(FALSE);
-
}
/**
*/
public function testRunWithImageField() {
CustomGroup::create(FALSE)
- ->addValue('name', 'TestSearchFields')
+ ->addValue('title', 'TestSearchFields')
->addValue('extends', 'Individual')
->execute()
->first();
$textField = 'text_field';
CustomGroup::create(FALSE)
- ->addValue('name', $group)
+ ->addValue('title', $group)
->addValue('extends', 'Contact')
->addValue('is_multiple', TRUE)
->addChain('field', CustomField::create()
*/
public function testWithSingleField(): void {
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyIndividualFields')
+ ->addValue('title', 'MyIndividualFields')
->addValue('extends', 'Individual')
->execute()
->first();
// First custom set
CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactFields')
+ ->addValue('title', 'MyContactFields')
->addValue('extends', 'Contact')
->addChain('field1', CustomField::create()
->addValue('label', 'FavColor')
// Second custom set
CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactFields2')
+ ->addValue('title', 'MyContactFields2')
->addValue('extends', 'Contact')
->addChain('field1', CustomField::create()
->addValue('label', 'FavColor')
$cgName = uniqid('RelFields');
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', $cgName)
+ ->addValue('title', $cgName)
->addValue('extends', 'Relationship')
->execute()
->first();
$cgName = uniqid('My');
CustomGroup::create(FALSE)
- ->addValue('name', $cgName)
+ ->addValue('title', $cgName)
->addValue('extends', 'Contact')
->addChain('field1', CustomField::create()
->addValue('label', 'FavColor')
$optionGroupCount = OptionGroup::get(FALSE)->selectRowCount()->execute()->count();
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyIndividualFields')
+ ->addValue('title', 'MyIndividualFields')
->addValue('extends', 'Individual')
->execute()
->first();
// Create 2 custom groups. Control group is to ensure updating one doesn't affect the other
foreach (['controlGroup', 'experimentalGroup'] as $groupName) {
$customGroups[$groupName] = CustomGroup::create(FALSE)
+ ->addValue('title', $groupName)
->addValue('name', $groupName)
->addValue('extends', 'Individual')
->execute()->first();
// Experimental group should be updated, control group should not
$this->assertEquals(['One' => 1, 'Three' => 2, 'Two' => 3, 'Four' => 4], $getValues('experimentalGroup'));
$this->assertEquals(['One' => 1, 'Two' => 2, 'Three' => 3, 'Four' => 4], $getValues('controlGroup'));
+
+ // Move first option to last position
+ CustomField::update(FALSE)
+ ->addWhere('custom_group_id.name', '=', 'experimentalGroup')
+ ->addWhere('name', '=', 'One')
+ ->addValue('weight', 4)
+ ->execute();
+ // Experimental group should be updated, control group should not
+ $this->assertEquals(['Three' => 1, 'Two' => 2, 'Four' => 3, 'One' => 4], $getValues('experimentalGroup'));
+ $this->assertEquals(['One' => 1, 'Two' => 2, 'Three' => 3, 'Four' => 4], $getValues('controlGroup'));
}
}
public function testWithContactRef() {
CustomGroup::create()
->setCheckPermissions(FALSE)
- ->addValue('name', 'TestActCus')
+ ->addValue('title', 'TestActCus')
->addValue('extends', 'Activity')
->addChain('field1', CustomField::create()
->addValue('label', 'FavPerson')
$optionValues = ['r' => 'Red', 'g' => 'Green', 'b' => 'Blue'];
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactFields')
+ ->addValue('title', 'MyContactFields')
->addValue('extends', 'Contact')
->execute()
->first();
$foodField = uniqid('fooda');
$customGroupId = CustomGroup::create(FALSE)
- ->addValue('name', $group)
+ ->addValue('title', $group)
->addValue('extends', 'Contact')
->execute()
->first()['id'];
->execute();
$customGroupId = CustomGroup::create(FALSE)
- ->addValue('name', 'FinancialStuff')
+ ->addValue('title', 'FinancialStuff')
->addValue('extends', 'Contact')
->execute()
->first()['id'];
$foodField = uniqid('foodb');
$customGroupId = CustomGroup::create(FALSE)
- ->addValue('name', $group)
+ ->addValue('title', $group)
->addValue('extends', 'Contact')
->execute()
->first()['id'];
->execute();
$customGroupId = CustomGroup::create(FALSE)
- ->addValue('name', 'FinancialStuff')
+ ->addValue('title', 'FinancialStuff')
->addValue('extends', 'Contact')
->execute()
->first()['id'];
$firstName = uniqid('fav');
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactRef')
+ ->addValue('title', 'MyContactRef')
->addValue('extends', 'Individual')
->execute()
->first();
$currentUser = $this->createLoggedInUser();
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactRef')
+ ->addValue('title', 'MyContactRef')
->addValue('extends', 'Individual')
->execute()
->first();
foreach ($groups as $name => $access) {
$singleGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'My' . ucfirst($name) . 'Single')
+ ->addValue('title', 'My' . ucfirst($name) . 'Single')
->addValue('extends', 'Individual')
->addChain('field', CustomField::create()
->addValue('label', 'MyField')
->execute()->single();
$v3['single'][$name] = 'custom_' . $singleGroup['field']['id'];
$multiGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'My' . ucfirst($name) . 'Multi')
+ ->addValue('title', 'My' . ucfirst($name) . 'Multi')
->addValue('extends', 'Individual')
->addValue('is_multiple', TRUE)
->addChain('field', CustomField::create()
$textFieldName = uniqid('txt');
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', $group)
+ ->addValue('title', $group)
->addValue('extends', 'Contact')
->addValue('is_multiple', TRUE)
->execute()
public function testGetWithNonStandardExtends() {
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactFields')
+ ->addValue('title', 'MyContactFields')
// not Contact
->addValue('extends', 'Individual')
->execute()
];
CustomGroup::create(FALSE)
- ->addValue('name', 'myPseudoconstantTest')
+ ->addValue('title', 'myPseudoconstantTest')
->addValue('extends', 'Individual')
->addChain('field1', CustomField::create()
->addValue('custom_group_id', '$id')
public function testCustomValueReplace() {
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'replaceTest')
+ ->addValue('title', 'replaceTest')
->addValue('extends', 'Contact')
->addValue('is_multiple', TRUE)
->execute()
public function testGetWithCustomData() {
$customGroup = CustomGroup::create(FALSE)
- ->addValue('name', 'MyContactFields')
+ ->addValue('title', 'MyContactFields')
->addValue('extends', 'Contact')
->execute()
->first();
"CustomGroup": [
{
"name": "MyFavoriteThings",
+ "title": "MyFavoriteThings",
"extends": "Contact"
}
],
}
+ public function testSaveContactWithImpliedType(): void {
+ // Ensure pseudoconstant suffix works
+ $result = Contact::create(FALSE)
+ ->addValue('contact_type:name', 'Household')
+ ->execute()->first();
+ $this->assertEquals('Household', $result['contact_type']);
+
+ // Contact type should be inferred by the type of name given
+ $result = Contact::save(FALSE)
+ ->addRecord(['organization_name' => 'Foo'])
+ ->execute()->first();
+ $this->assertEquals('Organization', $result['contact_type']);
+ }
+
}
public function testPseudoConstantOptionsWillBeAdded() {
$customGroupId = CustomGroup::create(FALSE)
- ->addValue('name', 'FavoriteThings')
+ ->addValue('title', 'FavoriteThings')
->addValue('extends', 'Contact')
->execute()
->first()['id'];
$options = ['r' => 'Red', 'g' => 'Green', 'p' => 'Pink'];
- CustomField::create(FALSE)
- ->addValue('label', 'FavColor')
- ->addValue('custom_group_id', $customGroupId)
- ->addValue('option_values', $options)
- ->addValue('html_type', 'Select')
- ->addValue('data_type', 'String')
+ CustomField::save(FALSE)
+ ->addRecord([
+ 'label' => 'FavColor',
+ 'custom_group_id' => $customGroupId,
+ 'option_values' => $options,
+ 'html_type' => 'Select',
+ 'data_type' => 'String',
+ ])
->execute();
$gatherer = new SpecGatherer();