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