From 118e964e5cbc8f7cc29f755d49325436a0ca0a41 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 7 Feb 2014 20:23:23 -0800 Subject: [PATCH] CRM-13970 - Option form url fix & test cleanup --- CRM/Admin/Form/Options.php | 17 ++++++++++------- CRM/Admin/Page/Options.php | 4 ++-- CRM/Core/Controller.php | 3 +++ CRM/Core/Form.php | 9 ++++++++- templates/CRM/ACL/Page/ACLBasic.tpl | 2 +- templates/CRM/Admin/Page/ConfigTaskList.tpl | 2 +- templates/CRM/Admin/Page/Options.tpl | 6 +++--- tests/phpunit/CiviTest/CiviSeleniumTestCase.php | 2 +- .../WebTest/ACL/AssignUsersToRolesTest.php | 2 +- .../Contribute/OfflineContributionTest.php | 2 +- .../WebTest/Grant/CustomFieldsetTest.php | 2 +- 11 files changed, 32 insertions(+), 19 deletions(-) diff --git a/CRM/Admin/Form/Options.php b/CRM/Admin/Form/Options.php index 2e610fe438..04a6908b8c 100644 --- a/CRM/Admin/Form/Options.php +++ b/CRM/Admin/Form/Options.php @@ -64,13 +64,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { public function preProcess() { parent::preProcess(); $session = CRM_Core_Session::singleton(); - if (!$this->_gName) { - $this->_gName = CRM_Utils_Request::retrieve('group', 'String', $this, FALSE, 0); - $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', - $this->_gName, - 'id', - 'name' - ); + if (!$this->_gName && !empty($this->urlPath[3])) { + $this->_gName = $this->urlPath[3]; + } + if (!$this->_gName && !empty($_GET['gid'])) { + $this->_gName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', (int) $_GET['gid'], 'name'); } if ($this->_gName) { $this->set('gName', $this->_gName); @@ -78,6 +76,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form { else { $this->_gName = $this->get('gName'); } + $this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', + $this->_gName, + 'id', + 'name' + ); $this->_gLabel = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gid, 'title'); $url = "civicrm/admin/options/{$this->_gName}"; $params = "reset=1"; diff --git a/CRM/Admin/Page/Options.php b/CRM/Admin/Page/Options.php index 270a5c8c0f..dfe1102de1 100644 --- a/CRM/Admin/Page/Options.php +++ b/CRM/Admin/Page/Options.php @@ -171,7 +171,7 @@ class CRM_Admin_Page_Options extends CRM_Core_Page_Basic { CRM_Core_Action::UPDATE => array( 'name' => ts('Edit'), 'url' => 'civicrm/admin/options/' . self::$_gName, - 'qs' => 'group=' . self::$_gName . '&action=update&id=%%id%%&reset=1', + 'qs' => 'action=update&id=%%id%%&reset=1', 'title' => ts('Edit %1', array(1 => self::$_gName)), ), CRM_Core_Action::DISABLE => array( @@ -187,7 +187,7 @@ class CRM_Admin_Page_Options extends CRM_Core_Page_Basic { CRM_Core_Action::DELETE => array( 'name' => ts('Delete'), 'url' => 'civicrm/admin/options/' . self::$_gName, - 'qs' => 'group=' . self::$_gName . '&action=delete&id=%%id%%', + 'qs' => 'action=delete&id=%%id%%', 'title' => ts('Delete %1 Type', array(1 => self::$_gName)), ), ); diff --git a/CRM/Core/Controller.php b/CRM/Core/Controller.php index 75230c1a9b..3b23add794 100644 --- a/CRM/Core/Controller.php +++ b/CRM/Core/Controller.php @@ -461,6 +461,9 @@ class CRM_Core_Controller extends HTML_QuickForm_Controller { if ($options) { $$stateName->setOptions($options); } + if (property_exists($$stateName, 'urlPath')) { + $$stateName->urlPath = explode('/', $_GET[CRM_Core_Config::singleton()->userFrameworkURLVar]); + } $this->addPage($$stateName); $this->addAction($stateName, new HTML_QuickForm_Action_Direct()); diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 382a76ce35..b3f6f1552d 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -105,6 +105,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page { */ public $ajaxResponse = array(); + /** + * Url path used to reach this page + * + * @var array + */ + public $urlPath = array(); + /** * Stores info about reference fields for preprocessing * Public so that hooks can access it @@ -924,7 +931,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page { if (!array_key_exists('placeholder', $props)) { $props['placeholder'] = $required ? ts('- select -') : ts('- none -'); } - if (!empty($props['placeholder']) && empty($props['multiple'])) { + if ($props['placeholder'] !== NULL && empty($props['multiple'])) { $options = array('' => '') + $options; } // Handle custom field diff --git a/templates/CRM/ACL/Page/ACLBasic.tpl b/templates/CRM/ACL/Page/ACLBasic.tpl index 3f8badf510..bf95eeddb4 100644 --- a/templates/CRM/ACL/Page/ACLBasic.tpl +++ b/templates/CRM/ACL/Page/ACLBasic.tpl @@ -24,7 +24,7 @@ +--------------------------------------------------------------------+ *} {capture assign=erURL}{crmURL p='civicrm/acl/entityrole' q='reset=1'}{/capture} -{capture assign=rolesURL}{crmURL p='civicrm/admin/options' q='group=acl_role&reset=1'}{/capture} +{capture assign=rolesURL}{crmURL p='civicrm/admin/options/acl_role' q='reset=1'}{/capture} {capture assign=docLink}{docURL page='user/initial-set-up/access-control' text='Access Control Documentation'}{/capture}
diff --git a/templates/CRM/Admin/Page/ConfigTaskList.tpl b/templates/CRM/Admin/Page/ConfigTaskList.tpl index 9082446f71..8aa11ee990 100644 --- a/templates/CRM/Admin/Page/ConfigTaskList.tpl +++ b/templates/CRM/Admin/Page/ConfigTaskList.tpl @@ -95,7 +95,7 @@ {ts}Settings for outbound email - either SMTP server, port and authentication or Sendmail path and argument.{/ts} - {ts}From Email Addresses{/ts} + {ts}From Email Addresses{/ts} {ts}Define general email address(es) that can be used as the FROM address when sending email to contacts from within CiviCRM (e.g. info@example.org){/ts} diff --git a/templates/CRM/Admin/Page/Options.tpl b/templates/CRM/Admin/Page/Options.tpl index 36474d1b20..87aaa6056a 100644 --- a/templates/CRM/Admin/Page/Options.tpl +++ b/templates/CRM/Admin/Page/Options.tpl @@ -72,7 +72,7 @@ {if $rows} {if $action ne 1 and $action ne 2} {/if}
@@ -155,14 +155,14 @@ {if $action ne 1 and $action ne 2} {/if}
{else}
- {capture assign=crmURL}{crmURL q="group="|cat:$gName|cat:"&action=add&reset=1"}{/capture} + {capture assign=crmURL}{crmURL p="civicrm/admin/options/$gName" q='action=add&reset=1'}{/capture} {ts 1=$crmURL}There are no option values entered. You can add one.{/ts}
{/if} diff --git a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php index 868b4e106a..b892411438 100644 --- a/tests/phpunit/CiviTest/CiviSeleniumTestCase.php +++ b/tests/phpunit/CiviTest/CiviSeleniumTestCase.php @@ -1747,7 +1747,7 @@ class CiviSeleniumTestCase extends PHPUnit_Extensions_SeleniumTestCase { } function addPaymentInstrument($label, $financialAccount) { - $this->openCiviPage('admin/options/payment_instrument', 'group=payment_instrument&action=add&reset=1', "_qf_Options_next-bottom"); + $this->openCiviPage('admin/options/payment_instrument', 'action=add&reset=1', "_qf_Options_next-bottom"); $this->type("label", $label); $this->select("financial_account_id", "value=$financialAccount"); $this->click("_qf_Options_next-bottom"); diff --git a/tests/phpunit/WebTest/ACL/AssignUsersToRolesTest.php b/tests/phpunit/WebTest/ACL/AssignUsersToRolesTest.php index 0e2886175a..8642442a1e 100755 --- a/tests/phpunit/WebTest/ACL/AssignUsersToRolesTest.php +++ b/tests/phpunit/WebTest/ACL/AssignUsersToRolesTest.php @@ -44,7 +44,7 @@ class WebTest_ACL_AssignUsersToRolesTest extends CiviSeleniumTestCase { $this->waitForText('crm-notification-container', "The Group '{$groupTitle}' has been saved."); - $this->openCiviPage("admin/options/acl_role", "group=acl_role&action=add&reset=1", "_qf_Options_cancel-bottom"); + $this->openCiviPage("admin/options/acl_role", "action=add&reset=1", "_qf_Options_cancel-bottom"); $label = "TestAclRole" . substr(sha1(rand()), 0, 4); $this->type("label", $label); diff --git a/tests/phpunit/WebTest/Contribute/OfflineContributionTest.php b/tests/phpunit/WebTest/Contribute/OfflineContributionTest.php index 255e209e3e..5d051f1b01 100644 --- a/tests/phpunit/WebTest/Contribute/OfflineContributionTest.php +++ b/tests/phpunit/WebTest/Contribute/OfflineContributionTest.php @@ -42,7 +42,7 @@ class WebTest_Contribute_OfflineContributionTest extends CiviSeleniumTestCase { $this->webtestAddContact($softCreditFname, $softCreditLname, FALSE); //financial account for check - $this->openCiviPage("admin/options/payment_instrument", "group=payment_instrument&reset=1"); + $this->openCiviPage("admin/options/payment_instrument", "reset=1"); $financialAccount = $this->getText("xpath=//div[@id='payment_instrument']/div[2]/table/tbody//tr/td[1][text()='Check']/../td[3]"); // Add new Financial Account diff --git a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php index a0c5ebef4a..1dc682d8b9 100644 --- a/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php +++ b/tests/phpunit/WebTest/Grant/CustomFieldsetTest.php @@ -49,7 +49,7 @@ class WebTest_Grant_CustomFieldsetTest extends CiviSeleniumTestCase { $rand = substr(sha1(rand()), 0, 7); // Add new Grant Type - $this->openCiviPage('admin/options/grant_type', 'group=grant_type&reset=1'); + $this->openCiviPage('admin/options/grant_type', 'reset=1'); $this->click("css=#grant_type > div.action-link > #new > span"); $this->waitForPageToLoad($this->getTimeoutMsec()); $grantType = 'GrantType' . $rand; -- 2.25.1