Merge pull request #15313 from yashodha/report_cleanup
[civicrm-core.git] / Civi / Api4 / Service / Spec / Provider / CustomValueSpecProvider.php
1 <?php
2
3 namespace Civi\Api4\Service\Spec\Provider;
4
5 use Civi\Api4\Service\Spec\FieldSpec;
6 use Civi\Api4\Service\Spec\RequestSpec;
7
8 class CustomValueSpecProvider implements Generic\SpecProviderInterface {
9
10 /**
11 * @inheritDoc
12 */
13 public function modifySpec(RequestSpec $spec) {
14 $action = $spec->getAction();
15 if ($action !== 'create') {
16 $idField = new FieldSpec('id', $spec->getEntity(), 'Integer');
17 $idField->setTitle(ts('Custom Value ID'));
18 $spec->addFieldSpec($idField);
19 }
20 $entityField = new FieldSpec('entity_id', $spec->getEntity(), 'Integer');
21 $entityField->setTitle(ts('Entity ID'));
22 $entityField->setRequired($action === 'create');
23 $entityField->setFkEntity('Contact');
24 $spec->addFieldSpec($entityField);
25 }
26
27 /**
28 * @inheritDoc
29 */
30 public function applies($entity, $action) {
31 return strstr($entity, 'Custom_');
32 }
33
34 }