Skip to content

Commit

Permalink
Merge pull request #25113 from colemanw/hideDeprecatedFields
Browse files Browse the repository at this point in the history
Hide deprecated fields from SearchKit & Afform
  • Loading branch information
demeritcowboy authored Dec 6, 2022
2 parents 133a8c5 + 6ff8ed2 commit 19660c1
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CRM/Activity/DAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ public static function &fields() {
'bao' => 'CRM_Activity_BAO_Activity',
'localizable' => 0,
'FKClassName' => 'CRM_Core_DAO_Phone',
'deprecated' => TRUE,
'html' => [
'type' => 'EntityRef',
'label' => ts("Phone (called)"),
Expand All @@ -515,6 +516,7 @@ public static function &fields() {
'entity' => 'Activity',
'bao' => 'CRM_Activity_BAO_Activity',
'localizable' => 0,
'deprecated' => TRUE,
'html' => [
'type' => 'Text',
],
Expand Down Expand Up @@ -662,6 +664,7 @@ public static function &fields() {
'bao' => 'CRM_Activity_BAO_Activity',
'localizable' => 0,
'FKClassName' => 'CRM_Contact_DAO_Relationship',
'deprecated' => TRUE,
'html' => [
'label' => ts("Relationship"),
],
Expand All @@ -679,6 +682,7 @@ public static function &fields() {
'entity' => 'Activity',
'bao' => 'CRM_Activity_BAO_Activity',
'localizable' => 0,
'deprecated' => TRUE,
'add' => '2.2',
],
'original_id' => [
Expand All @@ -692,6 +696,7 @@ public static function &fields() {
'bao' => 'CRM_Activity_BAO_Activity',
'localizable' => 0,
'FKClassName' => 'CRM_Activity_DAO_Activity',
'deprecated' => TRUE,
'html' => [
'label' => ts("Original Activity"),
],
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contact/DAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ public static function &fields() {
'entity' => 'Contact',
'bao' => 'CRM_Contact_BAO_Contact',
'localizable' => 0,
'deprecated' => TRUE,
'html' => [
'type' => 'Select',
'label' => ts("Preferred Mail Format"),
Expand Down Expand Up @@ -1582,6 +1583,7 @@ public static function &fields() {
'entity' => 'Contact',
'bao' => 'CRM_Contact_BAO_Contact',
'localizable' => 0,
'deprecated' => TRUE,
'html' => [
'type' => 'Text',
],
Expand Down
1 change: 1 addition & 0 deletions CRM/Core/DAO/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,7 @@ public static function &fields() {
'entity' => 'Address',
'bao' => 'CRM_Core_BAO_Address',
'localizable' => 0,
'deprecated' => TRUE,
'add' => '1.1',
],
'country_id' => [
Expand Down
1 change: 1 addition & 0 deletions CRM/Core/DAO/Phone.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public static function &fields() {
'entity' => 'Phone',
'bao' => 'CRM_Core_BAO_Phone',
'localizable' => 0,
'deprecated' => TRUE,
'add' => '1.1',
],
'phone' => [
Expand Down
5 changes: 5 additions & 0 deletions Civi/Api4/Generic/BasicGetFieldsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@ public function fields() {
'description' => 'True for auto-increment, calculated, or otherwise non-editable fields.',
'default_value' => FALSE,
],
[
'name' => 'deprecated',
'data_type' => 'Boolean',
'default_value' => FALSE,
],
[
'name' => 'output_formatters',
'data_type' => 'Array',
Expand Down
15 changes: 15 additions & 0 deletions Civi/Api4/Service/Spec/FieldSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class FieldSpec {
*/
public $readonly = FALSE;

/**
* @var bool
*/
public $deprecated = FALSE;

/**
* @var callable[]
*/
Expand Down Expand Up @@ -245,4 +250,14 @@ public function setReadonly($readonly) {
return $this;
}

/**
* @param bool $deprecated
* @return $this
*/
public function setDeprecated($deprecated) {
$this->deprecated = (bool) $deprecated;

return $this;
}

}
1 change: 1 addition & 0 deletions Civi/Api4/Service/Spec/SpecFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static function arrayToField(array $data, $entity) {
$field->setSerialize($data['serialize'] ?? NULL);
$field->setDefaultValue($data['default'] ?? NULL);
$field->setDescription($data['description'] ?? NULL);
$field->setDeprecated($data['deprecated'] ?? FALSE);
self::setInputTypeAndAttrs($field, $data, $dataTypeName);

$field->setPermission($data['permission'] ?? NULL);
Expand Down
2 changes: 1 addition & 1 deletion ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static function getFields($entityName, $params = []) {
'loadOptions' => ['id', 'label'],
'action' => 'create',
'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type', 'entity', 'fk_entity', 'readonly'],
'where' => [['input_type', 'IS NOT NULL']],
'where' => [['deprecated', '=', FALSE], ['input_type', 'IS NOT NULL']],
];
if (in_array($entityName, \CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$params['values']['contact_type'] = $entityName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function _run(\Civi\Api4\Generic\Result $result) {
->addSelect('name', 'title_plural')
->setChain([
'actions' => ['$name', 'getActions', ['where' => [['name', 'IN', ['update', 'delete']]]], 'name'],
'fields' => ['$name', 'getFields', ['where' => [['type', '=', 'Field']]], 'name'],
'fields' => ['$name', 'getFields', ['where' => [['deprecated', '=', FALSE], ['type', '=', 'Field']]], 'name'],
])
->execute()->first();

Expand Down
2 changes: 1 addition & 1 deletion ext/search_kit/Civi/Search/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static function getSchema(): array {
}
$getFields = civicrm_api4($entity['name'], 'getFields', [
'select' => ['name', 'title', 'label', 'description', 'type', 'options', 'input_type', 'input_attrs', 'data_type', 'serialize', 'entity', 'fk_entity', 'readonly', 'operators', 'suffixes', 'nullable'],
'where' => [['name', 'NOT IN', ['api_key', 'hash']]],
'where' => [['deprecated', '=', FALSE], ['name', 'NOT IN', ['api_key', 'hash']]],
'orderBy' => ['label'],
]);
foreach ($getFields as $field) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
action: 'update',
select: ['name', 'label', 'description', 'input_type', 'data_type', 'serialize', 'options', 'fk_entity', 'nullable'],
loadOptions: ['id', 'name', 'label', 'description', 'color', 'icon'],
where: [["readonly", "=", false]],
where: [['deprecated', '=', FALSE], ["readonly", "=", false]],
}).then(function(fields) {
ctrl.fields = fields;
});
Expand Down
4 changes: 3 additions & 1 deletion tests/phpunit/api/v4/Action/GetFieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function testPreloadFalse() {
$this->assertEquals(['name', 'label'], $fields['campaign_id']['suffixes']);
}

public function testRequiredAndNullable() {
public function testRequiredAndNullableAndDeprecated() {
$actFields = Activity::getFields(FALSE)
->setAction('create')
->execute()->indexBy('name');
Expand All @@ -111,6 +111,8 @@ public function testRequiredAndNullable() {
$this->assertFalse($actFields['activity_type_id']['nullable']);
$this->assertFalse($actFields['subject']['required']);
$this->assertTrue($actFields['subject']['nullable']);
$this->assertFalse($actFields['subject']['deprecated']);
$this->assertTrue($actFields['phone_id']['deprecated']);
}

public function testGetSuffixes() {
Expand Down
3 changes: 3 additions & 0 deletions xml/templates/dao.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ class {$table.className} extends CRM_Core_DAO {ldelim}
{if $field.uniqueTitle}
'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
{/if}
{if $field.deprecated}
'deprecated' => TRUE,
{/if}
{if $field.html}
'html' => array(
{foreach from=$field.html item=val key=key}
Expand Down

0 comments on commit 19660c1

Please sign in to comment.