The BAO supports these pseudo-fields during save operations, this exposes them to the api explorer.
+++ /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 |
- +--------------------------------------------------------------------+
- */
-
-/**
- *
- * @package CRM
- * @copyright CiviCRM LLC https://civicrm.org/licensing
- */
-
-
-namespace Civi\Api4\Service\Spec\Provider;
-
-use Civi\Api4\Service\Spec\FieldSpec;
-use Civi\Api4\Service\Spec\RequestSpec;
-
-class ActivityCreationSpecProvider implements Generic\SpecProviderInterface {
-
- /**
- * @inheritDoc
- */
- public function modifySpec(RequestSpec $spec) {
- $sourceContactField = new FieldSpec('source_contact_id', 'Activity', 'Integer');
- $sourceContactField->setRequired(TRUE);
- $sourceContactField->setFkEntity('Contact');
-
- $spec->addFieldSpec($sourceContactField);
- }
-
- /**
- * @inheritDoc
- */
- public function applies($entity, $action) {
- return $entity === 'Activity' && $action === '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 |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
+ */
+
+
+namespace Civi\Api4\Service\Spec\Provider;
+
+use Civi\Api4\Service\Spec\FieldSpec;
+use Civi\Api4\Service\Spec\RequestSpec;
+
+class ActivitySpecProvider implements Generic\SpecProviderInterface {
+
+ /**
+ * @inheritDoc
+ */
+ public function modifySpec(RequestSpec $spec) {
+ $action = $spec->getAction();
+
+ $field = new FieldSpec('source_contact_id', 'Activity', 'Integer');
+ $field->setTitle(ts('Source Contact'));
+ $field->setDescription(ts('Contact who created this activity.'));
+ $field->setRequired($action === 'create');
+ $field->setFkEntity('Contact');
+ $spec->addFieldSpec($field);
+
+ $field = new FieldSpec('target_contact_id', 'Activity', 'Array');
+ $field->setTitle(ts('Target Contacts'));
+ $field->setDescription(ts('Contact(s) involved in this activity.'));
+ $field->setFkEntity('Contact');
+ $spec->addFieldSpec($field);
+
+ $field = new FieldSpec('assignee_contact_id', 'Activity', 'Array');
+ $field->setTitle(ts('Assignee Contacts'));
+ $field->setDescription(ts('Contact(s) assigned to this activity.'));
+ $field->setFkEntity('Contact');
+ $spec->addFieldSpec($field);
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function applies($entity, $action) {
+ return $entity === 'Activity' && in_array($action, ['create', 'update'], TRUE);
+ }
+
+}
/**
* Test get returns target and assignee contacts.
+ * @dataProvider versionThreeAndFour
+ * @var int $version
*/
- public function testActivityReturnTargetAssignee() {
-
+ public function testActivityReturnTargetAssignee($version) {
+ $this->_apiversion = $version;
$description = "Demonstrates setting & retrieving activity target & source.";
$subfile = "GetTargetandAssignee";
$params = [
];
$result = $this->callAPIAndDocument('activity', 'create', $params, __FUNCTION__, __FILE__, $description, $subfile);
+
+ $actContacts = $this->callAPISuccess('ActivityContact', 'get', [
+ 'activity_id' => $result['id'],
+ ]);
+ $this->assertCount(3, $actContacts['values']);
+
+ if ($version === 4) {
+ $this->markTestIncomplete("APIv4 doesn't retrieve activity contacts directly.");
+ }
+
$result = $this->callAPISuccess('activity', 'get', [
'id' => $result['id'],
- 'version' => $this->_apiversion,
'return.assignee_contact_id' => 1,
'return.target_contact_id' => 1,
]);