Merge pull request #16152 from colemanw/multi
[civicrm-core.git] / Civi / Api4 / Generic / DAOGetFieldsAction.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
13/**
14 *
15 * @package CRM
ca5cec67 16 * @copyright CiviCRM LLC https://civicrm.org/licensing
380f3545
TO
17 * $Id$
18 *
19 */
20
21
19b53e5b
C
22namespace Civi\Api4\Generic;
23
24use Civi\Api4\Service\Spec\SpecFormatter;
25
26/**
27 * Get fields for a DAO-based entity.
28 *
29 * @method $this setIncludeCustom(bool $value)
30 * @method bool getIncludeCustom()
31 */
32class DAOGetFieldsAction extends BasicGetFieldsAction {
33
34 /**
35 * Include custom fields for this entity, or only core fields?
36 *
37 * @var bool
38 */
39 protected $includeCustom = TRUE;
40
41 /**
42 * Get fields for a DAO-based entity
43 *
44 * @return array
45 */
46 protected function getRecords() {
47 $fields = $this->_itemsToGet('name');
48 /** @var \Civi\Api4\Service\Spec\SpecGatherer $gatherer */
49 $gatherer = \Civi::container()->get('spec_gatherer');
50 // Any fields name with a dot in it is custom
51 if ($fields) {
52 $this->includeCustom = strpos(implode('', $fields), '.') !== FALSE;
53 }
54 $spec = $gatherer->getSpec($this->getEntityName(), $this->getAction(), $this->includeCustom);
55 return SpecFormatter::specToArray($spec->getFields($fields), $this->loadOptions);
56 }
57
58 public function fields() {
59 $fields = parent::fields();
f274627b
CW
60 $fields[] = [
61 'name' => 'help_pre',
62 'data_type' => 'String',
63 ];
64 $fields[] = [
65 'name' => 'help_post',
66 'data_type' => 'String',
67 ];
19b53e5b
C
68 $fields[] = [
69 'name' => 'custom_field_id',
70 'data_type' => 'Integer',
71 ];
72 $fields[] = [
73 'name' => 'custom_group_id',
74 'data_type' => 'Integer',
75 ];
76 return $fields;
77 }
78
79}