CRM-14078 - More consistent contact field labels
[civicrm-core.git] / CRM / Contact / Form / Edit / Address.php
index 5b3ca5596feb1a455a22f32d184765588328388b..35d2ed39c0155828d305148dab4fadf836d627b0 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -72,75 +72,60 @@ class CRM_Contact_Form_Edit_Address {
     }
 
     //make location type required for inline edit
-    $form->addSelect("address[$blockId][location_type_id]", array(
-        'entity' => 'address',
-        'class' => 'eight',
-      ) + $js, $inlineEdit);
+    $form->addField("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     }
 
-    $form->addElement(
-      'checkbox',
-      "address[$blockId][is_primary]",
-      ts('Primary location for this contact'),
-      ts('Primary location for this contact'),
-      $js
-    );
+    $form->addField(
+      "address[$blockId][is_primary]", array(
+        'entity' => 'address',
+        'label' => ts('Primary location for this contact'),
+        'text' => ts('Primary location for this contact')) + $js);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
 
-    $form->addElement(
-      'checkbox',
-      "address[$blockId][is_billing]",
-      ts('Billing location for this contact'),
-      ts('Billing location for this contact'),
-      $js
-    );
+    $form->addField(
+      "address[$blockId][is_billing]", array(
+        'entity' => 'address',
+        'label' => ts('Primary location for this contact'),
+        'text' => ts('Primary location for this contact')) + $js);
 
     // hidden element to store master address id
-    $form->addElement('hidden', "address[$blockId][master_id]");
-
+    $form->addField("address[$blockId][master_id]", array('entity' => 'address', 'type' => 'hidden'));
     $addressOptions = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
       'address_options', TRUE, NULL, TRUE
     );
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Address');
 
     $elements = array(
-      'address_name' => array(ts('Address Name'), $attributes['address_name'], NULL),
-      'street_address' => array(ts('Street Address'), $attributes['street_address'], NULL),
-      'supplemental_address_1' => array(ts('Supplemental Address 1'), $attributes['supplemental_address_1'], NULL),
-      'supplemental_address_2' => array(ts('Supplemental Address 2'), $attributes['supplemental_address_2'], NULL),
-      'city' => array(ts('City'), $attributes['city'], NULL),
-      'postal_code' => array(
-        ts('Zip / Postal Code'),
-        array_merge($attributes['postal_code'], array('class' => 'crm_postal_code')),
-        NULL,
-      ),
-      'postal_code_suffix' => array(
-        ts('Postal Code Suffix'),
-        array('size' => 4, 'maxlength' => 12, 'class' => 'crm_postal_code_suffix'),
-        NULL,
-      ),
-      'country_id' => array(ts('Country'), $attributes['country_id'], 'country'),
-      'state_province_id' => array(ts('State/Province'), $attributes['state_province_id'], NULL),
-      'county_id' => array(ts('County'), $attributes['county_id'], NULL),
-      'geo_code_1' => array(ts('Latitude'), array('size' => 9, 'maxlength' => 12), NULL),
-      'geo_code_2' => array(ts('Longitude'), array('size' => 9, 'maxlength' => 12), NULL),
-      'street_number' => array(ts('Street Number'), $attributes['street_number'], NULL),
-      'street_name' => array(ts('Street Name'), $attributes['street_name'], NULL),
-      'street_unit' => array(ts('Apt/Unit/Suite'), $attributes['street_unit'], NULL),
+      'address_name',
+      'street_address',
+      'supplemental_address_1',
+      'supplemental_address_2',
+      'city',
+      'postal_code',
+      'postal_code_suffix',
+      'country_id',
+      'state_province_id',
+      'county_id',
+      'geo_code_1',
+      'geo_code_2',
+      'street_number',
+      'street_name',
+      'street_unit',
     );
 
-    foreach ($elements as $name => $v) {
-      list($title, $attributes, $select) = $v;
-
+    foreach ($elements as $name) {
+      //Remove id from name, to allow comparison against enabled addressOtions.
       $nameWithoutID = strpos($name, '_id') !== FALSE ? substr($name, 0, -3) : $name;
+      // Skip fields which are not enabled in the address options.
       if (empty($addressOptions[$nameWithoutID])) {
         $continue = TRUE;
+        //Don't skip street parsed fields when parsing is enabled.
         if (in_array($nameWithoutID, array(
             'street_number',
             'street_name',
@@ -153,35 +138,17 @@ class CRM_Contact_Form_Edit_Address {
           continue;
         }
       }
-
-      //build normal select if country is not present in address block
-      if ($name == 'state_province_id' && !$addressOptions['country']) {
-        $select = 'stateProvince';
+      if ($name == 'address_name') {
+        $name = 'name';
       }
 
-      if (!$select) {
-        if ($name == 'state_province_id' || $name == 'county_id') {
-          $form->addChainSelect("address[$blockId][$name]");
-        }
-        else {
-          if ($name == 'address_name') {
-            $name = 'name';
-          }
+      $params = array('entity' => 'address');
 
-          $form->addElement('text',
-            "address[$blockId][$name]",
-            $title,
-            $attributes
-          );
-        }
-      }
-      else {
-        $form->addElement('select',
-          "address[$blockId][$name]",
-          $title,
-          array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select()
-        );
+      if ($name == 'postal_code_suffix') {
+        $params['label'] = ts('Suffix');
       }
+
+      $form->addField("address[$blockId][$name]", $params);
     }
 
     $entityId = NULL;