Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pseudoconstant to UFField dao #14041

Merged
merged 1 commit into from
Apr 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions CRM/Core/BAO/UFField.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,24 +1061,32 @@ public static function getAvailableFields($gid = NULL, $defaults = []) {
*
* @param bool $force
*
* @return array, multidimensional; e.g. $result['field_name']['label']
* @return array
* e.g. $result['field_name']['label']
*/
public static function getAvailableFieldsFlat($force = FALSE) {
// FIXME reset when data model changes
static $result = NULL;
if ($result === NULL || $force) {
$fieldTree = self::getAvailableFields();
$result = [];
foreach ($fieldTree as $field_type => $fields) {
foreach ($fields as $field_name => $field) {
if (!isset($result[$field_name])) {
$field['field_type'] = $field_type;
$result[$field_name] = $field;
if (!isset(Civi::$statics['UFFieldsFlat']) || $force) {
Civi::$statics['UFFieldsFlat'] = [];
foreach (self::getAvailableFields() as $fieldType => $fields) {
foreach ($fields as $fieldName => $field) {
if (!isset(Civi::$statics['UFFieldsFlat'][$fieldName])) {
$field['field_type'] = $fieldType;
Civi::$statics['UFFieldsFlat'][$fieldName] = $field;
}
}
}
}
return $result;
return Civi::$statics['UFFieldsFlat'];
}

/**
* Get a list of fields which can be added to profiles in the format [name => title]
*
* @return array
*/
public static function getAvailableFieldTitles() {
$fields = self::getAvailableFieldsFlat();
return CRM_Utils_Array::collect('title', $fields);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion CRM/Core/DAO/UFField.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/UFField.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:efbfbe95aac7abe98b31ab715965b57f)
* (GenCodeChecksum:c73a4661d33e4dde2240d6d8ac7fd2c4)
*/

/**
Expand Down Expand Up @@ -236,6 +236,9 @@ public static function &fields() {
'entity' => 'UFField',
'bao' => 'CRM_Core_BAO_UFField',
'localizable' => 0,
'pseudoconstant' => [
'callback' => 'CRM_Core_BAO_UFField::getAvailableFieldTitles',
]
],
'is_active' => [
'name' => 'is_active',
Expand Down
3 changes: 3 additions & 0 deletions xml/schema/Core/UFField.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<length>64</length>
<required>true</required>
<comment>Name for CiviCRM field which is being exposed for sharing.</comment>
<pseudoconstant>
<callback>CRM_Core_BAO_UFField::getAvailableFieldTitles</callback>
</pseudoconstant>
<add>1.1</add>
</field>
<field>
Expand Down