From 844c89d4e04a5bb818ef42192f945b15274f6ce4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 30 Nov 2021 13:02:43 +1300 Subject: [PATCH] [Smarty Variables] Remove isset from location type form https://dmaster.localhost:32353/civicrm/admin/locationType?reset=1 --- CRM/Admin/Page/LocationType.php | 20 ++++ CRM/Core/Page/Basic.php | 132 ++++++++++++---------- templates/CRM/Admin/Page/LocationType.tpl | 6 +- tests/phpunit/CRM/Core/FormTest.php | 3 + 4 files changed, 98 insertions(+), 63 deletions(-) diff --git a/CRM/Admin/Page/LocationType.php b/CRM/Admin/Page/LocationType.php index 45de123bcf..0b8b902276 100644 --- a/CRM/Admin/Page/LocationType.php +++ b/CRM/Admin/Page/LocationType.php @@ -107,4 +107,24 @@ class CRM_Admin_Page_LocationType extends CRM_Core_Page_Basic { return 'civicrm/admin/locationType'; } + /** + * @param $sort + * @param $action + * @param array $links + * + * @return array + */ + protected function getRows($sort, $action, array $links): array { + $rows = parent::getRows($sort, $action, $links); + foreach ($rows as &$row) { + // prevent smarty notices. + foreach (['is_default', 'class', 'vcard_name'] as $expectedField) { + if (!isset($row['is_default'])) { + $row[$expectedField] = NULL; + } + } + } + return $rows; + } + } diff --git a/CRM/Core/Page/Basic.php b/CRM/Core/Page/Basic.php index 097ba8b6c0..21b522032b 100644 --- a/CRM/Core/Page/Basic.php +++ b/CRM/Core/Page/Basic.php @@ -203,67 +203,8 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { if ($action & CRM_Core_Action::ENABLE) { $action -= CRM_Core_Action::ENABLE; } - $baoString = $this->getBAOName(); - $object = new $baoString(); - - $values = []; - - // lets make sure we get the stuff sorted by name if it exists - $fields = &$object->fields(); - $key = ''; - if (!empty($fields['title'])) { - $key = 'title'; - } - elseif (!empty($fields['label'])) { - $key = 'label'; - } - elseif (!empty($fields['name'])) { - $key = 'name'; - } - - if (trim($sort)) { - $object->orderBy($sort); - } - elseif ($key) { - $object->orderBy($key . ' asc'); - } - $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE); - // find all objects - $object->find(); - while ($object->fetch()) { - if (!isset($object->mapping_type_id) || - // "1 for Search Builder" - $object->mapping_type_id != 1 - ) { - $permission = CRM_Core_Permission::EDIT; - if ($key) { - $permission = $this->checkPermission($object->id, $object->$key); - } - if ($permission) { - $values[$object->id] = []; - CRM_Core_DAO::storeValues($object, $values[$object->id]); - - if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) { - if (isset($values[$object->id]['contact_type_a'])) { - $values[$object->id]['contact_type_a_display'] = $contactTypes[$values[$object->id]['contact_type_a']]; - } - if (isset($values[$object->id]['contact_type_b'])) { - $values[$object->id]['contact_type_b_display'] = $contactTypes[$values[$object->id]['contact_type_b']]; - } - } - - // populate action links - $this->action($object, $action, $values[$object->id], $links, $permission); - - if (isset($object->mapping_type_id)) { - $mappintTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id'); - $values[$object->id]['mapping_type'] = $mappintTypes[$object->mapping_type_id]; - } - } - } - } - $this->assign('rows', $values); + $this->assign('rows', $this->getRows($sort, $action, $links)); } /** @@ -395,4 +336,75 @@ abstract class CRM_Core_Page_Basic extends CRM_Core_Page { $controller->run(); } + /** + * @param $sort + * @param $action + * @param array $links + * + * @return array + */ + protected function getRows($sort, $action, array $links): array { + $baoString = $this->getBAOName(); + $object = new $baoString(); + + $values = []; + + // lets make sure we get the stuff sorted by name if it exists + $fields = &$object->fields(); + $key = ''; + if (!empty($fields['title'])) { + $key = 'title'; + } + elseif (!empty($fields['label'])) { + $key = 'label'; + } + elseif (!empty($fields['name'])) { + $key = 'name'; + } + + if (trim($sort)) { + $object->orderBy($sort); + } + elseif ($key) { + $object->orderBy($key . ' asc'); + } + + $contactTypes = CRM_Contact_BAO_ContactType::getSelectElements(FALSE, FALSE); + // find all objects + $object->find(); + while ($object->fetch()) { + if (!isset($object->mapping_type_id) || + // "1 for Search Builder" + $object->mapping_type_id != 1 + ) { + $permission = CRM_Core_Permission::EDIT; + if ($key) { + $permission = $this->checkPermission($object->id, $object->$key); + } + if ($permission) { + $values[$object->id] = []; + CRM_Core_DAO::storeValues($object, $values[$object->id]); + + if (is_a($object, 'CRM_Contact_DAO_RelationshipType')) { + if (isset($values[$object->id]['contact_type_a'])) { + $values[$object->id]['contact_type_a_display'] = $contactTypes[$values[$object->id]['contact_type_a']]; + } + if (isset($values[$object->id]['contact_type_b'])) { + $values[$object->id]['contact_type_b_display'] = $contactTypes[$values[$object->id]['contact_type_b']]; + } + } + + // populate action links + $this->action($object, $action, $values[$object->id], $links, $permission); + + if (isset($object->mapping_type_id)) { + $mappintTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Mapping', 'mapping_type_id'); + $values[$object->id]['mapping_type'] = $mappintTypes[$object->mapping_type_id]; + } + } + } + } + return $values; + } + } diff --git a/templates/CRM/Admin/Page/LocationType.tpl b/templates/CRM/Admin/Page/LocationType.tpl index 80e8b716aa..3ce80083fb 100644 --- a/templates/CRM/Admin/Page/LocationType.tpl +++ b/templates/CRM/Admin/Page/LocationType.tpl @@ -34,13 +34,13 @@ {foreach from=$rows item=row} - + {$row.name} {$row.display_name} - {if !empty($row.vcard_name)}{$row.vcard_name}{/if} + {$row.vcard_name} {$row.description} {if $row.is_active eq 1} {ts}Yes{/ts} {else} {ts}No{/ts} {/if} - {if isset($row.is_default)}{icon condition=$row.is_default}{ts}Default{/ts}{/icon} {/if} + {if $row.is_default}{icon condition=$row.is_default}{ts}Default{/ts}{/icon} {/if} {$row.action|replace:'xx':$row.id} {/foreach} diff --git a/tests/phpunit/CRM/Core/FormTest.php b/tests/phpunit/CRM/Core/FormTest.php index 958efb1b1c..03c19affd6 100644 --- a/tests/phpunit/CRM/Core/FormTest.php +++ b/tests/phpunit/CRM/Core/FormTest.php @@ -50,6 +50,9 @@ class CRM_Core_FormTest extends CiviUnitTestCase { 'Add New Tag' => [ 'civicrm/tag/edit?action=add&parent_id=', ], + 'Location Type' => [ + 'civicrm/admin/locationType?reset=1', + ], 'Assign Account to Financial Type' => [ 'civicrm/admin/financial/financialType/accounts?action=add&reset=1&aid=1', ], -- 2.25.1