From: colemanw Date: Sun, 8 Oct 2023 02:31:03 +0000 (-0400) Subject: Apiv4 - Fix setting defaults for Group.title and SearchDisplay.label X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ddeb320f618dacc69dcb4e679928fbcdac83f3f6;p=civicrm-core.git Apiv4 - Fix setting defaults for Group.title and SearchDisplay.label --- diff --git a/CRM/Contact/BAO/Group.php b/CRM/Contact/BAO/Group.php index 3a5b8b7b81..7c777557d7 100644 --- a/CRM/Contact/BAO/Group.php +++ b/CRM/Contact/BAO/Group.php @@ -344,9 +344,11 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { 'parents' => NULL, ]; + // Fill title and frontend_title if not supplied + if (empty($params['id']) && empty($params['title'])) { + $params['title'] = $params['frontend_title'] ?? $params['name']; + } if (empty($params['id']) && empty($params['frontend_title'])) { - // If we were calling writeRecord it would handle this, but we need - // to migrate the other bits of magic. $params['frontend_title'] = $params['title']; } $hook = empty($params['id']) ? 'create' : 'edit'; @@ -388,6 +390,8 @@ class CRM_Contact_BAO_Group extends CRM_Contact_DAO_Group { // form the name only if missing: CRM-627 $nameParam = $params['name'] ?? NULL; + // If we were calling writeRecord it would handle this, but we need + // to migrate the other bits of magic. if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } diff --git a/Civi/Test/Api4TestTrait.php b/Civi/Test/Api4TestTrait.php index b78e81c7b2..80ae3c6ecf 100644 --- a/Civi/Test/Api4TestTrait.php +++ b/Civi/Test/Api4TestTrait.php @@ -130,9 +130,9 @@ trait Api4TestTrait { foreach ($requiredFields as $fieldName => $field) { if ( !isset($values[$fieldName]) && - ($field['required'] || AbstractAction::evaluateCondition($field['required_if'], $values + $extraValues)) + ($field['required'] || AbstractAction::evaluateCondition($field['required_if'], ['values' => $values + $extraValues])) ) { - $extraValues[$fieldName] = $this->getRequiredValue($field, $requiredFields); + $extraValues[$fieldName] = $this->getRequiredValue($field); } } diff --git a/ext/search_kit/Civi/Api4/Service/Spec/Provider/SearchDisplayCreationSpecProvider.php b/ext/search_kit/Civi/Api4/Service/Spec/Provider/SearchDisplayCreationSpecProvider.php index 963e63ef2d..618ecad574 100644 --- a/ext/search_kit/Civi/Api4/Service/Spec/Provider/SearchDisplayCreationSpecProvider.php +++ b/ext/search_kit/Civi/Api4/Service/Spec/Provider/SearchDisplayCreationSpecProvider.php @@ -24,8 +24,7 @@ class SearchDisplayCreationSpecProvider extends \Civi\Core\Service\AutoService i * @inheritDoc */ public function modifySpec(RequestSpec $spec) { - $spec->getFieldByName('name')->setRequired(FALSE)->setRequiredIf('empty($values.label)'); - $spec->getFieldByName('label')->setRequired(FALSE)->setRequiredIf('empty($values.name)'); + $spec->getFieldByName('name')->setRequired(FALSE); } /** diff --git a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php index 0dba79e959..d25f36ced9 100644 --- a/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php +++ b/ext/search_kit/tests/phpunit/api/v4/SearchDisplay/SearchRunTest.php @@ -83,7 +83,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, @@ -197,7 +197,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, @@ -270,7 +270,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -356,7 +356,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -466,7 +466,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, @@ -556,7 +556,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => FALSE, @@ -802,7 +802,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { 'saved_search_id' => '$id', 'name' => $displayName, 'type' => 'table', - 'label' => '', + 'label' => 'TestDisplay', 'acl_bypass' => TRUE, 'settings' => [ 'limit' => 20, @@ -979,7 +979,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'list', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, @@ -1496,7 +1496,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -1861,7 +1861,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -1914,7 +1914,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, @@ -1952,7 +1952,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -2072,7 +2072,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'actions' => TRUE, 'pager' => [], @@ -2162,7 +2162,7 @@ class SearchRunTest extends Api4TestBase implements TransactionalInterface { ], 'display' => [ 'type' => 'table', - 'label' => '', + 'label' => 'tesdDisplay', 'settings' => [ 'limit' => 20, 'pager' => TRUE, diff --git a/tests/phpunit/api/v3/GroupTest.php b/tests/phpunit/api/v3/GroupTest.php index f0d8fd5fa8..6ca4662cbf 100644 --- a/tests/phpunit/api/v3/GroupTest.php +++ b/tests/phpunit/api/v3/GroupTest.php @@ -42,30 +42,6 @@ class api_v3_GroupTest extends CiviUnitTestCase { parent::tearDown(); } - /** - * Test missing required title parameter results in an error. - * - * @param int $version - * - * @dataProvider versionThreeAndFour - */ - public function testGroupCreateNoTitle($version) { - $this->_apiversion = $version; - $params = [ - 'name' => 'Test Group No title ', - 'domain_id' => 1, - 'description' => 'New Test Group Created', - 'is_active' => 1, - 'visibility' => 'Public Pages', - 'group_type' => [ - '1' => 1, - '2' => 1, - ], - ]; - - $this->callAPIFailure('group', 'create', $params, 'title'); - } - /** * @param int $version *