WordReplacement - Use generic writeRecords/deleteRecords which call hooks
[civicrm-core.git] / Civi / Api4 / Service / Spec / Provider / FieldDomainIdSpecProvider.php
CommitLineData
19b53e5b
C
1<?php
2
380f3545
TO
3/*
4 +--------------------------------------------------------------------+
41498ac5 5 | Copyright CiviCRM LLC. All rights reserved. |
380f3545 6 | |
41498ac5
TO
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
380f3545
TO
10 +--------------------------------------------------------------------+
11 */
12
19b53e5b
C
13namespace Civi\Api4\Service\Spec\Provider;
14
15use Civi\Api4\Service\Spec\RequestSpec;
16
60142ef9 17class FieldDomainIdSpecProvider implements Generic\SpecProviderInterface {
19b53e5b
C
18
19 /**
60142ef9 20 * Generic create spec function to set sensible defaults for any entity with a "domain_id" field.
19b53e5b
C
21 */
22 public function modifySpec(RequestSpec $spec) {
60142ef9 23 $domainIdField = $spec->getFieldByName('domain_id');
de6cd515
CW
24 // TODO: The WordReplacement entity should have domain_id required so this OR condition can be removed
25 if ($domainIdField && ($domainIdField->isRequired() || $domainIdField->getEntity() === 'WordReplacement')) {
60142ef9
CW
26 $domainIdField->setRequired(FALSE)->setDefaultValue('current_domain');;
27 }
19b53e5b
C
28 }
29
30 /**
31 * @inheritDoc
32 */
33 public function applies($entity, $action) {
60142ef9 34 return $action === 'create';
19b53e5b
C
35 }
36
37}