Merge pull request #15818 from colemanw/fields
[civicrm-core.git] / Civi / Api4 / Service / Spec / Provider / CustomValueSpecProvider.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 |
10 +--------------------------------------------------------------------+
11 */
12
13 /**
14 *
15 * @package CRM
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 * $Id$
18 *
19 */
20
21
22 namespace Civi\Api4\Service\Spec\Provider;
23
24 use Civi\Api4\Service\Spec\FieldSpec;
25 use Civi\Api4\Service\Spec\RequestSpec;
26
27 class CustomValueSpecProvider implements Generic\SpecProviderInterface {
28
29 /**
30 * @inheritDoc
31 */
32 public function modifySpec(RequestSpec $spec) {
33 $action = $spec->getAction();
34 if ($action !== 'create') {
35 $idField = new FieldSpec('id', $spec->getEntity(), 'Integer');
36 $idField->setTitle(ts('Custom Value ID'));
37 $spec->addFieldSpec($idField);
38 }
39 $entityField = new FieldSpec('entity_id', $spec->getEntity(), 'Integer');
40 $entityField->setTitle(ts('Entity ID'));
41 $entityField->setRequired($action === 'create');
42 $entityField->setFkEntity('Contact');
43 $spec->addFieldSpec($entityField);
44 }
45
46 /**
47 * @inheritDoc
48 */
49 public function applies($entity, $action) {
50 return strstr($entity, 'Custom_');
51 }
52
53 }