-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22322 from colemanw/groupContactDefaults
APIv4 - Set default status when creating GroupContact record
- Loading branch information
Showing
3 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
Civi/Api4/Service/Spec/Provider/GroupContactCreationSpecProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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\Service\Spec\Provider; | ||
|
||
use Civi\Api4\Service\Spec\RequestSpec; | ||
|
||
class GroupContactCreationSpecProvider implements Generic\SpecProviderInterface { | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function modifySpec(RequestSpec $spec) { | ||
$spec->getFieldByName('status')->setDefaultValue('Added'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function applies($entity, $action) { | ||
return $entity === 'GroupContact' && $action === 'create'; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?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 api\v4\Entity; | ||
|
||
use api\v4\UnitTestCase; | ||
use Civi\Api4\GroupContact; | ||
|
||
/** | ||
* @group headless | ||
*/ | ||
class GroupContactTest extends UnitTestCase { | ||
|
||
public function testCreate() { | ||
$contact = $this->createEntity(['type' => 'Individual']); | ||
$group = $this->createEntity(['type' => 'Group']); | ||
$result = GroupContact::create(FALSE) | ||
->addValue('group_id', $group['id']) | ||
->addValue('contact_id', $contact['id']) | ||
->execute() | ||
->first(); | ||
$this->assertEquals('Added', $result['status']); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters