diff options
Diffstat (limited to 'www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Generic/DAOGetFieldsAction.php')
-rw-r--r-- | www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Generic/DAOGetFieldsAction.php | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Generic/DAOGetFieldsAction.php b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Generic/DAOGetFieldsAction.php new file mode 100644 index 00000000..e86d99bc --- /dev/null +++ b/www/crm/wp-content/plugins/civicrm/civicrm/ext/api4/Civi/Api4/Generic/DAOGetFieldsAction.php @@ -0,0 +1,53 @@ +<?php + +namespace Civi\Api4\Generic; + +use Civi\Api4\Service\Spec\SpecGatherer; +use Civi\Api4\Service\Spec\SpecFormatter; + +/** + * Get fields for a DAO-based entity. + * + * @method $this setIncludeCustom(bool $value) + * @method bool getIncludeCustom() + */ +class DAOGetFieldsAction extends BasicGetFieldsAction { + + /** + * Include custom fields for this entity, or only core fields? + * + * @var bool + */ + protected $includeCustom = TRUE; + + /** + * Get fields for a DAO-based entity + * + * @return array + */ + protected function getRecords() { + $fields = $this->_itemsToGet('name'); + /** @var SpecGatherer $gatherer */ + $gatherer = \Civi::container()->get('spec_gatherer'); + // Any fields name with a dot in it is custom + if ($fields) { + $this->includeCustom = strpos(implode('', $fields), '.') !== FALSE; + } + $spec = $gatherer->getSpec($this->getEntityName(), $this->action, $this->includeCustom); + return SpecFormatter::specToArray($spec->getFields($fields), (array) $this->select, $this->loadOptions); + } + + public function fields() { + $fields = parent::fields(); + $fields[] = [ + 'name' => 'custom_field_id', + 'data_type' => 'Integer', + ]; + $fields[] = [ + 'name' => 'custom_group_id', + 'data_type' => 'Integer', + ]; + return $fields; + } + +} |