CRM-17357 - Conditional label for Name / Email search fields based on search setting.
authorDave Greenberg <dave@civicrm.org>
Wed, 11 Nov 2015 19:52:28 +0000 (11:52 -0800)
committerDave Greenberg <dave@civicrm.org>
Wed, 11 Nov 2015 19:52:28 +0000 (11:52 -0800)
----------------------------------------
* CRM-17357: PHP fatal error during creation of receipt PDF
  https://issues.civicrm.org/jira/browse/CRM-17357

CRM/Activity/Form/Search.php
CRM/Case/Form/Search.php
CRM/Contact/Form/Search/Basic.php
CRM/Contribute/Form/Search.php
CRM/Core/Form/Search.php
CRM/Event/Form/Search.php
CRM/Grant/Form/Search.php
CRM/Member/Form/Search.php
CRM/Pledge/Form/Search.php

index fa0a9db5d8a95d13d35052723dcc0a28c5a15e8c..ba25b59755c90cab8879e275f84e3974bf6de705 100644 (file)
@@ -166,7 +166,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text', 'sort_name', ts('Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
+    $this->addSortNameField();
 
     CRM_Activity_BAO_Query::buildSearchForm($this);
 
index a43f10585f3e0d390c21089232184ab1afc65f89..d1c08247db68454b2210863eaab66d77384e0c28 100644 (file)
@@ -171,11 +171,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text',
-      'sort_name',
-      ts('Client Name or Email'),
-      CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
-    );
+    $this->addSortNameField();
 
     CRM_Case_BAO_Query::buildSearchForm($this);
 
@@ -201,6 +197,28 @@ class CRM_Case_Form_Search extends CRM_Core_Form_Search {
 
   }
 
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Client Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Client Name');
+  }
+
   /**
    * The post processing of the form gets done here.
    *
index c49b90a638a7aa6defe15b78cceced30e4fda7ee..e6c2bb7f22a5d1d71aa46ec408a352dec68ff5e9 100644 (file)
@@ -57,10 +57,7 @@ class CRM_Contact_Form_Search_Basic extends CRM_Contact_Form_Search {
    * @return void
    */
   public function buildQuickForm() {
-    // text for sort_name or email criteria
-    $config = CRM_Core_Config::singleton();
-    $label = empty($config->includeEmailInName) ? ts('Name') : ts('Name or Email');
-    $this->add('text', 'sort_name', $label);
+    $this->addSortNameField();
 
     $searchOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
       'advanced_search_options'
index e6635b93ba9fdf453fd12d0686b5ea1499ccb12f..3158716bc4f1af564b7d7172980a42efe685dade 100644 (file)
@@ -168,14 +168,7 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    // text for sort_name
-    $this->addElement('text',
-      'sort_name',
-      ts('Contributor Name or Email'),
-      CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact',
-        'sort_name'
-      )
-    );
+    $this->addSortNameField();
 
     $this->_group = CRM_Core_PseudoConstant::nestedGroup();
 
@@ -216,6 +209,28 @@ class CRM_Contribute_Form_Search extends CRM_Core_Form_Search {
 
   }
 
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Contributor Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Contributor Name');
+  }
+
   /**
    * The post processing of the form gets done here.
    *
index 5a610b57fa289f077f000fffe73405c41acccc81..99c66f3da7b837c8c02f5f27f8c9bc3042720bf8 100644 (file)
@@ -150,4 +150,44 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Add the sort-name field to the form.
+   *
+   * There is a setting to determine whether email is included in the search & we look this up to determine
+   * which text to choose.
+   *
+   * Note that for translation purposes the full string works better than using 'prefix' hence we use override-able functions
+   * to define the string.
+   */
+  protected function addSortNameField() {
+    $this->addElement(
+      'text',
+      'sort_name',
+      civicrm_api3('setting', 'getvalue', array('name' => 'includeEmailInName', 'group' => 'Search Preferences')) ? $this->getSortNameLabelWithEmail() : $this->getSortNameLabelWithOutEmail(),
+      CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
+    );
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Name');
+  }
+
 }
index 5d77cbfd574b2f7ccfb701a3855110e9fdcbde7e..f71addcb2f4b0d792092ff600caa73130bcccf11 100644 (file)
@@ -170,7 +170,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
+    $this->addSortNameField();
 
     CRM_Event_BAO_Query::buildSearchForm($this);
 
@@ -241,6 +241,28 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
 
   }
 
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Participant Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Participant Name');
+  }
+
   /**
    * The post processing of the form gets done here.
    *
index 4b4c307e70735bd1c818eccb0bc59b098cc88563..7f09be2bc294c2b9ed11d20133802d46c3c118f2 100644 (file)
@@ -162,7 +162,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text', 'sort_name', ts('Name or Email'), array('class' => 'twenty') + CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
+    $this->addSortNameField();
 
     CRM_Grant_BAO_Query::buildSearchForm($this);
 
index 796b54b04f7547f61a00f8bfc0bc3def3ae802c0..09f14305aef9d4267760946da74e3f99b9ba105d 100644 (file)
@@ -160,7 +160,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text', 'sort_name', ts('Member Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
+    $this->addSortNameField();
 
     CRM_Member_BAO_Query::buildSearchForm($this);
 
@@ -177,6 +177,28 @@ class CRM_Member_Form_Search extends CRM_Core_Form_Search {
 
   }
 
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Member Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Member Name');
+  }
+
   /**
    * The post processing of the form gets done here.
    *
index 74914ced03cf8ad0f348a08ad63115dd9a2c98b2..8670624f8dddec99a5e8064d51c140c277f704e0 100644 (file)
@@ -158,7 +158,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search {
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
-    $this->addElement('text', 'sort_name', ts('Pledger Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
+    $this->addSortNameField();
 
     CRM_Pledge_BAO_Query::buildSearchForm($this);
 
@@ -175,6 +175,28 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form_Search {
 
   }
 
+  /**
+   * Get the label for the sortName field if email searching is on.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithEmail() {
+    return ts('Pledger Name or Email');
+  }
+
+  /**
+   * Get the label for the sortName field if email searching is off.
+   *
+   * (email searching is a setting under search preferences).
+   *
+   * @return string
+   */
+  protected function getSortNameLabelWithOutEmail() {
+    return ts('Pledger Name');
+  }
+
   /**
    * The post processing of the form gets done here.
    *