Merge pull request #5078 from eileenmcnaughton/comment-full-stops
[civicrm-core.git] / CRM / Core / Form.php
index 084b5450ed7c5cccd60f2b071189f15d2cfe083d..1ecbbede88734d9c028a39123c08580e2f606b53 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * This is our base form. It is part of the Form/Controller/StateMachine
@@ -152,7 +152,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   private $_chainSelectFields = array();
 
   /**
-   * Constructor for the basic form page
+   * Constructor for the basic form page.
    *
    * We should not use QuickForm directly. This class provides a lot
    * of default convenient functions, rules and buttons
@@ -167,7 +167,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    * @return \CRM_Core_Form
    */
-  function __construct(
+  public function __construct(
     $state = NULL,
     $action = CRM_Core_Action::NONE,
     $method = 'post',
@@ -218,18 +218,34 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * Register all the standard rules that most forms potentially use
    *
    * @return void
-   *
    */
   public function registerRules() {
     static $rules = array(
-      'title', 'longTitle', 'variable', 'qfVariable',
-      'phone', 'integer', 'query',
-      'url', 'wikiURL',
-      'domain', 'numberOfDigit',
-      'date', 'currentDate',
-      'asciiFile', 'htmlFile', 'utf8File',
-      'objectExists', 'optionExists', 'postalCode', 'money', 'positiveInteger',
-      'xssString', 'fileExists', 'autocomplete', 'validContact',
+      'title',
+      'longTitle',
+      'variable',
+      'qfVariable',
+      'phone',
+      'integer',
+      'query',
+      'url',
+      'wikiURL',
+      'domain',
+      'numberOfDigit',
+      'date',
+      'currentDate',
+      'asciiFile',
+      'htmlFile',
+      'utf8File',
+      'objectExists',
+      'optionExists',
+      'postalCode',
+      'money',
+      'positiveInteger',
+      'xssString',
+      'fileExists',
+      'autocomplete',
+      'validContact',
     );
 
     foreach ($rules as $rule) {
@@ -251,7 +267,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    * @return HTML_QuickForm_Element could be an error object
    */
-  function &add(
+  public function &add(
     $type, $name, $label = '',
     $attributes = '', $required = FALSE, $extra = NULL
   ) {
@@ -294,20 +310,19 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   }
 
   /**
-   * This function is called before buildForm. Any pre-processing that
+   * called before buildForm. Any pre-processing that
    * needs to be done for buildForm should be done here
    *
    * This is a virtual function and should be redefined if needed
    *
    *
    * @return void
-   *
    */
   public function preProcess() {
   }
 
   /**
-   * This function is called after the form is validated. Any
+   * called after the form is validated. Any
    * processing of form state etc should be done in this function.
    * Typically all processing associated with a form should be done
    * here and relevant state should be stored in the session
@@ -316,13 +331,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    *
    * @return void
-   *
    */
   public function postProcess() {
   }
 
   /**
-   * This function is just a wrapper, so that we can call all the hook functions
+   * just a wrapper, so that we can call all the hook functions
    * @param bool $allowAjax
    *   FIXME: This feels kind of hackish, ideally we would take the json-related code from this function.
    *                          and bury it deeper down in the controller
@@ -332,7 +346,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $this->postProcessHook();
 
     // Respond with JSON if in AJAX context (also support legacy value '6')
-    if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(CRM_Core_Smarty::PRINT_JSON, 6))) {
+    if ($allowAjax && !empty($_REQUEST['snippet']) && in_array($_REQUEST['snippet'], array(
+          CRM_Core_Smarty::PRINT_JSON,
+          6,
+        ))
+    ) {
       $this->ajaxResponse['buttonName'] = str_replace('_qf_' . $this->getAttribute('id') . '_', '', $this->controller->getButtonName());
       $this->ajaxResponse['action'] = $this->_action;
       if (isset($this->_id) || isset($this->id)) {
@@ -343,12 +361,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   }
 
   /**
-   * The postProcess hook is typically called by the framework
+   * The postProcess hook is typically called by the framework.
    * However in a few cases, the form exits or redirects early in which
    * case it needs to call this function so other modules can do the needful
    * Calling this function directly should be avoided if possible. In general a
    * better way is to do setUserContext so the framework does the redirect
-   *
    */
   public function postProcessHook() {
     CRM_Utils_Hook::postProcess(get_class($this), $this);
@@ -361,7 +378,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    *
    * @return void
-   *
    */
   public function buildQuickForm() {
   }
@@ -372,10 +388,11 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    * access        public
    *
-   * @return array reference to the array of default values
-   *
+   * @return array|NULL
+   *   reference to the array of default values
    */
   public function setDefaultValues() {
+    return NULL;
   }
 
   /**
@@ -385,7 +402,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *
    *
    * @return void
-   *
    */
   public function addRules() {
   }
@@ -393,7 +409,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Performs the server side validation
    * @since     1.0
-   * @return    boolean   true if no error found
+   * @return bool
+   *   true if no error found
    * @throws    HTML_QuickForm_Error
    */
   public function validate() {
@@ -431,7 +448,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * Core function that builds the form. We redefine this function
    * here and expect all CRM forms to build their form in the function
    * buildQuickForm.
-   *
    */
   public function buildForm() {
     $this->_formBuilt = TRUE;
@@ -475,10 +491,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
 
     //Set html data-attribute to enable warning user of unsaved changes
     if ($this->unsavedChangesWarn === TRUE
-        || (!isset($this->unsavedChangesWarn)
-           && ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE)
-           )
-        ) {
+      || (!isset($this->unsavedChangesWarn)
+        && ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE)
+      )
+    ) {
       $this->setAttribute('data-warn-changes', 'true');
     }
   }
@@ -486,34 +502,34 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Add default Next / Back buttons
    *
-   * @param array array of associative arrays in the order in which the buttons should be
-   *                displayed. The associate array has 3 fields: 'type', 'name' and 'isDefault'
-   *                The base form class will define a bunch of static arrays for commonly used
-   *                formats
+   * @param array $params
+   *   Array of associative arrays in the order in which the buttons should be
+   *   displayed. The associate array has 3 fields: 'type', 'name' and 'isDefault'
+   *   The base form class will define a bunch of static arrays for commonly used
+   *   formats.
    *
    * @return void
-   *
-   *
    */
   public function addButtons($params) {
-    $prevnext = array();
-    $spacing = array();
+    $prevnext = $spacing = array();
     foreach ($params as $button) {
-      $js = CRM_Utils_Array::value('js', $button);
-      $isDefault = CRM_Utils_Array::value('isDefault', $button, FALSE);
-      if ($isDefault) {
-        $attrs = array('class' => 'crm-form-submit default');
-      }
-      else {
-        $attrs = array('class' => 'crm-form-submit');
+      $attrs = array('class' => 'crm-form-submit') + (array) CRM_Utils_Array::value('js', $button);
+
+      if (!empty($button['class'])) {
+        $attrs['class'] .= ' ' . $button['class'];
       }
 
-      if ($js) {
-        $attrs = array_merge($js, $attrs);
+      if (!empty($button['isDefault'])) {
+        $attrs['class'] .= ' default';
       }
 
-      if ($button['type'] === 'cancel') {
+      if (in_array($button['type'], array('upload', 'next', 'submit', 'done', 'process', 'refresh'))) {
+        $attrs['class'] .= ' validate';
+        $defaultIcon = 'check';
+      }
+      else {
         $attrs['class'] .= ' cancel';
+        $defaultIcon = $button['type'] == 'back' ? 'triangle-1-w' : 'close';
       }
 
       if ($button['type'] === 'reset') {
@@ -521,15 +537,25 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       }
       else {
         if (!empty($button['subName'])) {
-          $buttonName = $this->getButtonName($button['type'], $button['subName']);
-        }
-        else {
-          $buttonName = $this->getButtonName($button['type']);
+          if ($button['subName'] == 'new') {
+            $defaultIcon = 'plus';
+          }
+          if ($button['subName'] == 'done') {
+            $defaultIcon = 'circle-check';
+          }
+          if ($button['subName'] == 'next') {
+            $defaultIcon = 'circle-triangle-e';
+          }
         }
 
         if (in_array($button['type'], array('next', 'upload', 'done')) && $button['name'] === ts('Save')) {
-          $attrs = array_merge($attrs, (array('accesskey' => 'S')));
+          $attrs['accesskey'] = 'S';
+        }
+        $icon = CRM_Utils_Array::value('icon', $button, $defaultIcon);
+        if ($icon) {
+          $attrs['crm-icon'] = $icon;
         }
+        $buttonName = $this->getButtonName($button['type'], CRM_Utils_Array::value('subName', $button));
         $prevnext[] = $this->createElement('submit', $buttonName, $button['name'], $attrs);
       }
       if (!empty($button['isDefault'])) {
@@ -599,7 +625,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Setter function for options
    *
-   * @param mixed
+   * @param mixed $options
    *
    * @return void
    */
@@ -622,7 +648,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Boolean function to determine if this is a one form page
    *
-   * @return boolean
+   * @return bool
    */
   public function isSimpleForm() {
     return $this->_state->getType() & (CRM_Core_State::START | CRM_Core_State::FINISH);
@@ -640,7 +666,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Setter function for Form Action
    *
-   * @param string
+   * @param string $action
    *
    * @return void
    */
@@ -689,9 +715,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       $tplname = $ext->getTemplatePath(CRM_Utils_System::getClassName($this)) . DIRECTORY_SEPARATOR . $filename;
     }
     else {
-      $tplname = str_replace('_',
-        DIRECTORY_SEPARATOR,
-        CRM_Utils_System::getClassName($this)
+      $tplname = strtr(
+        CRM_Utils_System::getClassName($this),
+        array(
+          '_' => DIRECTORY_SEPARATOR,
+          '\\' => DIRECTORY_SEPARATOR,
+        )
       ) . '.tpl';
     }
     return $tplname;
@@ -742,12 +771,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Store the variable with the value in the form scope
    *
-   * @param string name : name of the variable
-   * @param mixed value : value of the variable
-   *
+   * @param string $name
+   *   Name of the variable.
+   * @param mixed $value
+   *   Value of the variable.
    *
    * @return void
-   *
    */
   public function set($name, $value) {
     $this->controller->set($name, $value);
@@ -756,11 +785,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Get the variable from the form scope
    *
-   * @param string name : name of the variable
-   *
+   * @param string $name
+   *   Name of the variable
    *
    * @return mixed
-   *
    */
   public function get($name) {
     return $this->controller->get($name);
@@ -876,7 +904,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   public function addYesNo($id, $title, $allowClear = FALSE, $required = NULL, $attributes = array()) {
     $attributes += array('id_suffix' => $id);
-    $choice   = array();
+    $choice = array();
     $choice[] = $this->createElement('radio', NULL, '11', ts('Yes'), '1', $attributes);
     $choice[] = $this->createElement('radio', NULL, '11', ts('No'), '0', $attributes);
 
@@ -900,7 +928,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @param string $separator
    * @param bool $flipValues
    */
-  function addCheckBox(
+  public function addCheckBox(
     $id, $title, $values, $other = NULL,
     $attributes = NULL, $required = NULL,
     $javascriptMethod = NULL,
@@ -1051,7 +1079,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     // Core field
     else {
       $info = civicrm_api3($props['entity'], 'getfields');
-      foreach($info['values'] as $uniqueName => $fieldSpec) {
+      foreach ($info['values'] as $uniqueName => $fieldSpec) {
         if (
           $uniqueName === $props['field'] ||
           CRM_Utils_Array::value('name', $fieldSpec) === $props['field'] ||
@@ -1115,8 +1143,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       'editor_id'
     );
     $editor = strtolower(CRM_Utils_Array::value($editorID,
-        CRM_Core_OptionGroup::values('wysiwyg_editor')
-      ));
+      CRM_Core_OptionGroup::values('wysiwyg_editor')
+    ));
     if (!$editor || $forceTextarea) {
       $editor = 'textarea';
     }
@@ -1155,7 +1183,8 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   public function addCountry($id, $title, $required = NULL, $extra = NULL) {
     $this->addElement('select', $id, $title,
       array(
-        '' => ts('- select -')) + CRM_Core_PseudoConstant::country(), $extra
+        '' => ts('- select -'),
+      ) + CRM_Core_PseudoConstant::country(), $extra
     );
     if ($required) {
       $this->addRule($id, ts('Please select %1', array(1 => $title)), 'required');
@@ -1257,21 +1286,23 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
 
   /**
    * Add date
-   * @param string $name
-   *   Name of the element.
-   * @param string $label
-   *   Label of the element.
-   * @param array $attributes
-   *   Key / value pair.
    *
+   * @code
    * // if you need time
    * $attributes = array(
    *   'addTime' => true,
    *   'formatType' => 'relative' or 'birth' etc check advanced date settings
    * );
+   * @endcode
+   *
+   * @param string $name
+   *   Name of the element.
+   * @param string $label
+   *   Label of the element.
    * @param bool $required
    *   True if required.
-   *
+   * @param array $attributes
+   *   Key / value pair.
    */
   public function addDate($name, $label, $required = FALSE, $attributes = NULL) {
     if (!empty($attributes['formatType'])) {
@@ -1369,7 +1400,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Add a currency and money element to the form
    */
-  function addMoney(
+  public function addMoney(
     $name,
     $label,
     $required = FALSE,
@@ -1392,7 +1423,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Add currency element to the form
    */
-  function addCurrency(
+  public function addCurrency(
     $name = 'currency',
     $label = NULL,
     $required = TRUE,
@@ -1422,17 +1453,17 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @param string $label
    * @param array $props
    *   Mix of html and widget properties, including:.
-   *  - select - params to give to select2 widget
-   *  - entity - defaults to contact
-   *  - create - can the user create a new entity on-the-fly?
+   *   - select - params to give to select2 widget
+   *   - entity - defaults to contact
+   *   - create - can the user create a new entity on-the-fly?
    *             Set to TRUE if entity is contact and you want the default profiles,
    *             or pass in your own set of links. @see CRM_Core_BAO_UFGroup::getCreateLinks for format
    *             note that permissions are checked automatically
-   *  - api - array of settings for the getlist api wrapper
+   *   - api - array of settings for the getlist api wrapper
    *          note that it accepts a 'params' setting which will be passed to the underlying api
-   *  - placeholder - string
-   *  - multiple - bool
-   *  - class, etc. - other html properties
+   *   - placeholder - string
+   *   - multiple - bool
+   *   - class, etc. - other html properties
    * @param bool $required
    *
    * @return HTML_QuickForm_Element
@@ -1486,17 +1517,17 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @todo standardise the format which dates are passed to the BAO layer in & remove date
    * handling from BAO
    */
-  public function convertDateFieldsToMySQL(&$params){
-    foreach ($this->_dateFields as $fieldName => $specs){
-      if(!empty($params[$fieldName])){
+  public function convertDateFieldsToMySQL(&$params) {
+    foreach ($this->_dateFields as $fieldName => $specs) {
+      if (!empty($params[$fieldName])) {
         $params[$fieldName] = CRM_Utils_Date::isoToMysql(
           CRM_Utils_Date::processDate(
-          $params[$fieldName],
-          CRM_Utils_Array::value("{$fieldName}_time", $params), TRUE)
+            $params[$fieldName],
+            CRM_Utils_Array::value("{$fieldName}_time", $params), TRUE)
         );
       }
-      else{
-        if(isset($specs['default'])){
+      else {
+        if (isset($specs['default'])) {
           $params[$fieldName] = date('YmdHis', strtotime($specs['default']));
         }
       }
@@ -1523,7 +1554,6 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
   /**
    * Function that can be defined in Form to override or
    * perform specific action on cancel action
-   *
    */
   public function cancelAction() {
   }
@@ -1542,21 +1572,21 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
 
   /**
    * Get contact if for a form object. Prioritise
-   *  - cid in URL if 0 (on behalf on someoneelse)
+   *   - cid in URL if 0 (on behalf on someoneelse)
    *      (@todo consider setting a variable if onbehalf for clarity of downstream 'if's
-   *  - logged in user id if it matches the one in the cid in the URL
-   *  - contact id validated from a checksum from a checksum
-   *  - cid from the url if the caller has ACL permission to view
-   *  - fallback is logged in user (or ? NULL if no logged in user) (@todo wouldn't 0 be more intuitive?)
+   *   - logged in user id if it matches the one in the cid in the URL
+   *   - contact id validated from a checksum from a checksum
+   *   - cid from the url if the caller has ACL permission to view
+   *   - fallback is logged in user (or ? NULL if no logged in user) (@todo wouldn't 0 be more intuitive?)
    *
-   * @return mixed NULL|integer
+   * @return NULL|int
    */
   public function getContactID() {
     $tempID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
-    if(isset($this->_params) && isset($this->_params['select_contact_id'])) {
+    if (isset($this->_params) && isset($this->_params['select_contact_id'])) {
       $tempID = $this->_params['select_contact_id'];
     }
-    if(isset($this->_params, $this->_params[0]) && !empty($this->_params[0]['select_contact_id'])) {
+    if (isset($this->_params, $this->_params[0]) && !empty($this->_params[0]['select_contact_id'])) {
       // event form stores as an indexed array, contribution form not so much...
       $tempID = $this->_params[0]['select_contact_id'];
     }
@@ -1587,7 +1617,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       }
     }
     // check if user has permission, CRM-12062
-    else if ($tempID && CRM_Contact_BAO_Contact_Permission::allow($tempID)) {
+    elseif ($tempID && CRM_Contact_BAO_Contact_Permission::allow($tempID)) {
       return $tempID;
     }
 
@@ -1620,38 +1650,41 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    *   Ids of profiles that are on the form (to be autofilled).
    * @param array $autoCompleteField
    *
-   *  - name_field
-   *  - id_field
-   *  - url (for ajax lookup)
+   *   - name_field
+   *   - id_field
+   *   - url (for ajax lookup)
    *
    * @todo add data attributes so we can deal with multiple instances on a form
    */
   public function addAutoSelector($profiles = array(), $autoCompleteField = array()) {
     $autoCompleteField = array_merge(array(
-        'id_field' => 'select_contact_id',
-        'placeholder' => ts('Select someone else ...'),
-        'show_hide' => TRUE,
-        'api' => array('params' => array('contact_type' => 'Individual'))
-      ), $autoCompleteField);
+      'id_field' => 'select_contact_id',
+      'placeholder' => ts('Select someone else ...'),
+      'show_hide' => TRUE,
+      'api' => array('params' => array('contact_type' => 'Individual')),
+    ), $autoCompleteField);
 
-    if($this->canUseAjaxContactLookups()) {
+    if ($this->canUseAjaxContactLookups()) {
       $this->assign('selectable', $autoCompleteField['id_field']);
-      $this->addEntityRef($autoCompleteField['id_field'], NULL, array('placeholder' => $autoCompleteField['placeholder'], 'api' => $autoCompleteField['api']));
+      $this->addEntityRef($autoCompleteField['id_field'], NULL, array(
+          'placeholder' => $autoCompleteField['placeholder'],
+          'api' => $autoCompleteField['api'],
+        ));
 
       CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/AlternateContactSelector.js', 1, 'html-header')
-      ->addSetting(array(
-      'form' => array('autocompletes' => $autoCompleteField),
-      'ids' => array('profile' => $profiles),
-      ));
+        ->addSetting(array(
+          'form' => array('autocompletes' => $autoCompleteField),
+          'ids' => array('profile' => $profiles),
+        ));
     }
   }
 
   /**
-   *
    */
   public function canUseAjaxContactLookups() {
     if (0 < (civicrm_api3('contact', 'getcount', array('check_permissions' => 1))) &&
-      CRM_Core_Permission::check(array(array('access AJAX API', 'access CiviCRM')))) {
+      CRM_Core_Permission::check(array(array('access AJAX API', 'access CiviCRM')))
+    ) {
       return TRUE;
     }
   }
@@ -1663,20 +1696,22 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * that small pieces of duplication are not being refactored into separate functions because their only shared parent
    * is this form. Inserting a class FrontEndForm.php between the contribution & event & this class would allow functions like this
    * and a dozen other small ones to be refactored into a shared parent with the reduction of much code duplication
+   *
+   * @param $onlinePaymentProcessorEnabled
    */
   public function addCIDZeroOptions($onlinePaymentProcessorEnabled) {
     $this->assign('nocid', TRUE);
     $profiles = array();
-    if($this->_values['custom_pre_id']) {
+    if ($this->_values['custom_pre_id']) {
       $profiles[] = $this->_values['custom_pre_id'];
     }
-    if($this->_values['custom_post_id']) {
+    if ($this->_values['custom_post_id']) {
       $profiles = array_merge($profiles, (array) $this->_values['custom_post_id']);
     }
-    if($onlinePaymentProcessorEnabled) {
+    if ($onlinePaymentProcessorEnabled) {
       $profiles[] = 'billing';
     }
-    if(!empty($this->_values)) {
+    if (!empty($this->_values)) {
       $this->addAutoSelector($profiles);
     }
   }
@@ -1691,7 +1726,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    * @return array
    */
   public function getProfileDefaults($profile_id = 'Billing', $contactID = NULL) {
-    try{
+    try {
       $defaults = civicrm_api3('profile', 'getsingle', array(
         'profile_id' => (array) $profile_id,
         'contact_id' => $contactID,
@@ -1756,7 +1791,12 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
    */
   public function addChainSelect($elementName, $settings = array()) {
     $props = $settings += array(
-      'control_field' => str_replace(array('state_province', 'StateProvince', 'county', 'County'), array('country', 'Country', 'state_province', 'StateProvince'), $elementName),
+      'control_field' => str_replace(array('state_province', 'StateProvince', 'county', 'County'), array(
+          'country',
+          'Country',
+          'state_province',
+          'StateProvince',
+        ), $elementName),
       'data-callback' => strpos($elementName, 'rovince') ? 'civicrm/ajax/jqState' : 'civicrm/ajax/jqCounty',
       'label' => strpos($elementName, 'rovince') ? ts('State/Province') : ts('County'),
       'data-empty-prompt' => strpos($elementName, 'rovince') ? ts('Choose country first') : ts('Choose state first'),
@@ -1848,4 +1888,5 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       }
     }
   }
+
 }