From 9813ae79c77cb6b8da403da44b2ab6cb8664ce60 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 29 Oct 2020 11:33:19 -0400 Subject: [PATCH] APIv4 - Fix nonstandard camelCase of title_plural field --- Civi/Api4/Action/Entity/Get.php | 4 ++-- Civi/Api4/Entity.php | 6 +++++- Civi/Api4/Generic/AbstractEntity.php | 2 +- ext/search/CRM/Search/Page/Ang.php | 4 ++-- ext/search/ang/search/SaveSmartGroup.ctrl.js | 2 +- ext/search/ang/search/crmSearch.component.js | 8 ++++---- ext/search/ang/search/crmSearch.html | 2 +- .../ang/search/crmSearchActions.component.js | 2 +- .../crmSearchActions/crmSearchActionUpdate.html | 2 +- tests/phpunit/api/v4/Entity/ConformanceTest.php | 15 ++++++++++++++- 10 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Civi/Api4/Action/Entity/Get.php b/Civi/Api4/Action/Entity/Get.php index 2d14f325be..3b8484e16f 100644 --- a/Civi/Api4/Action/Entity/Get.php +++ b/Civi/Api4/Action/Entity/Get.php @@ -96,8 +96,8 @@ class Get extends \Civi\Api4\Generic\BasicGetAction { $entities[$fieldName] = [ 'name' => $fieldName, 'title' => $customEntity['title'], - 'titlePlural' => $customEntity['title'], - 'description' => ts('Custom group for %1', [1 => $baseEntity::getInfo()['titlePlural']]), + 'title_plural' => $customEntity['title'], + 'description' => ts('Custom group for %1', [1 => $baseEntity::getInfo()['title_plural']]), 'see' => [ 'https://docs.civicrm.org/user/en/latest/organising-your-data/creating-custom-fields/#multiple-record-fieldsets', '\\Civi\\Api4\\CustomGroup', diff --git a/Civi/Api4/Entity.php b/Civi/Api4/Entity.php index 49f39859ec..8a3b7771b9 100644 --- a/Civi/Api4/Entity.php +++ b/Civi/Api4/Entity.php @@ -50,7 +50,11 @@ class Entity extends Generic\AbstractEntity { ], [ 'name' => 'title', - 'description' => 'Localized title', + 'description' => 'Localized title (singular)', + ], + [ + 'name' => 'title_plural', + 'description' => 'Localized title (plural)', ], [ 'name' => 'type', diff --git a/Civi/Api4/Generic/AbstractEntity.php b/Civi/Api4/Generic/AbstractEntity.php index 8084614b14..d777526f0d 100644 --- a/Civi/Api4/Generic/AbstractEntity.php +++ b/Civi/Api4/Generic/AbstractEntity.php @@ -123,7 +123,7 @@ abstract class AbstractEntity { $info = [ 'name' => static::getEntityName(), 'title' => static::getEntityTitle(), - 'titlePlural' => static::getEntityTitle(TRUE), + 'title_plural' => static::getEntityTitle(TRUE), 'type' => self::stripNamespace(get_parent_class(static::class)), ]; $reflection = new \ReflectionClass(static::class); diff --git a/ext/search/CRM/Search/Page/Ang.php b/ext/search/CRM/Search/Page/Ang.php index 22cab1dcfa..3916bb7a89 100644 --- a/ext/search/CRM/Search/Page/Ang.php +++ b/ext/search/CRM/Search/Page/Ang.php @@ -84,9 +84,9 @@ class CRM_Search_Page_Ang extends CRM_Core_Page { */ private function getSchema() { $schema = \Civi\Api4\Entity::get() - ->addSelect('name', 'title', 'titlePlural', 'description', 'icon') + ->addSelect('name', 'title', 'title_plural', 'description', 'icon') ->addWhere('name', '!=', 'Entity') - ->addOrderBy('titlePlural') + ->addOrderBy('title_plural') ->setChain([ 'get' => ['$name', 'getActions', ['where' => [['name', '=', 'get']]], ['params']], ])->execute(); diff --git a/ext/search/ang/search/SaveSmartGroup.ctrl.js b/ext/search/ang/search/SaveSmartGroup.ctrl.js index 47837b2c8c..90be034966 100644 --- a/ext/search/ang/search/SaveSmartGroup.ctrl.js +++ b/ext/search/ang/search/SaveSmartGroup.ctrl.js @@ -28,7 +28,7 @@ if ((entityName === 'Contact' && field.name === 'id') || field.fk_entity === 'Contact') { columns.push({ id: prefix + field.name, - text: entity.titlePlural + (entityCount[entityName] ? ' ' + entityCount[entityName] : '') + ': ' + field.label, + text: entity.title_plural + (entityCount[entityName] ? ' ' + entityCount[entityName] : '') + ': ' + field.label, icon: entity.icon }); } diff --git a/ext/search/ang/search/crmSearch.component.js b/ext/search/ang/search/crmSearch.component.js index 49c9908172..8bb66ef210 100644 --- a/ext/search/ang/search/crmSearch.component.js +++ b/ext/search/ang/search/crmSearch.component.js @@ -27,7 +27,7 @@ $scope.controls = {}; $scope.joinTypes = [{k: false, v: ts('Optional')}, {k: true, v: ts('Required')}]; - $scope.entities = formatForSelect2(CRM.vars.search.schema, 'name', 'titlePlural', ['description', 'icon']); + $scope.entities = formatForSelect2(CRM.vars.search.schema, 'name', 'title_plural', ['description', 'icon']); this.perm = { editGroups: CRM.checkPerm('edit groups') }; @@ -44,7 +44,7 @@ if (entity) { joinEntities.push({ id: link.entity + ' AS ' + link.alias, - text: entity.titlePlural, + text: entity.title_plural, description: '(' + link.alias + ')', icon: entity.icon }); @@ -428,7 +428,7 @@ var mainEntity = searchMeta.getEntity(ctrl.entity), result = [{ - text: mainEntity.titlePlural, + text: mainEntity.title_plural, icon: mainEntity.icon, children: formatFields(ctrl.entity, '') }]; @@ -436,7 +436,7 @@ var joinName = join[0].split(' AS '), joinEntity = searchMeta.getEntity(joinName[0]); result.push({ - text: joinEntity.titlePlural + ' (' + joinName[1] + ')', + text: joinEntity.title_plural + ' (' + joinName[1] + ')', icon: joinEntity.icon, children: formatFields(joinEntity.name, joinName[1] + '.') }); diff --git a/ext/search/ang/search/crmSearch.html b/ext/search/ang/search/crmSearch.html index 5c6a010e37..782bfdd790 100644 --- a/ext/search/ang/search/crmSearch.html +++ b/ext/search/ang/search/crmSearch.html @@ -1,5 +1,5 @@ diff --git a/tests/phpunit/api/v4/Entity/ConformanceTest.php b/tests/phpunit/api/v4/Entity/ConformanceTest.php index ec372c4e37..91ec3a3df0 100644 --- a/tests/phpunit/api/v4/Entity/ConformanceTest.php +++ b/tests/phpunit/api/v4/Entity/ConformanceTest.php @@ -116,6 +116,7 @@ class ConformanceTest extends UnitTestCase { public function testConformance($entity) { $entityClass = 'Civi\Api4\\' . $entity; + $this->checkEntityInfo($entityClass); $actions = $this->checkActions($entityClass); // Go no further if it's not a CRUD entity @@ -136,7 +137,19 @@ class ConformanceTest extends UnitTestCase { } /** - * @param string $entityClass + * @param \Civi\Api4\Generic\AbstractEntity|string $entityClass + */ + protected function checkEntityInfo($entityClass) { + $info = $entityClass::getInfo(); + $this->assertNotEmpty($info['name']); + $this->assertNotEmpty($info['title']); + $this->assertNotEmpty($info['title_plural']); + $this->assertNotEmpty($info['type']); + $this->assertNotEmpty($info['description']); + } + + /** + * @param \Civi\Api4\Generic\AbstractEntity|string $entityClass * @param string $entity */ protected function checkFields($entityClass, $entity) { -- 2.25.1