From 999ab5e13bd4576f5f9e2721bdae6482140243ce Mon Sep 17 00:00:00 2001 From: Tim Mallezie Date: Fri, 8 May 2015 18:14:08 +0200 Subject: [PATCH] use addfield in addressForm --- CRM/Contact/Form/Edit/Address.php | 107 ++++++------------ CRM/Core/Form.php | 4 +- .../Form/Edit/Address/city_postal_code.tpl | 5 +- xml/schema/Core/Address.xml | 69 ++++++++++- 4 files changed, 108 insertions(+), 77 deletions(-) diff --git a/CRM/Contact/Form/Edit/Address.php b/CRM/Contact/Form/Edit/Address.php index f1fd17bb52..b6cdd6b7f9 100644 --- a/CRM/Contact/Form/Edit/Address.php +++ b/CRM/Contact/Form/Edit/Address.php @@ -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,11 @@ 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'; - } - - $form->addElement('text', - "address[$blockId][$name]", - $title, - $attributes - ); - } - } - else { - $form->addElement('select', - "address[$blockId][$name]", - $title, - array('' => ts('- select -')) + CRM_Core_PseudoConstant::$select() - ); - } + $form->addField("address[$blockId][$name]", array('entity' => 'address')); } $entityId = NULL; diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index 4bddc368b0..7badffb79b 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -1294,7 +1294,9 @@ class CRM_Core_Form extends HTML_QuickForm_Page { //case 'AdvMulti-Select': case 'CheckBox': - $this->add('checkbox', $name, $label, NULL, $required); + $text = isset($props['text']) ? $props['text'] : NULL; + unset($props['text']); + $this->addElement('checkbox', $name, $label, $text, $props); break; case 'File': diff --git a/templates/CRM/Contact/Form/Edit/Address/city_postal_code.tpl b/templates/CRM/Contact/Form/Edit/Address/city_postal_code.tpl index 210a510a2b..d30647c855 100644 --- a/templates/CRM/Contact/Form/Edit/Address/city_postal_code.tpl +++ b/templates/CRM/Contact/Form/Edit/Address/city_postal_code.tpl @@ -34,10 +34,13 @@ {/if} {if !empty($form.address.$blockId.postal_code)} - {$form.address.$blockId.postal_code.label}{if !empty($form.address.$blockId.postal_code_suffix)} {ts}Suffix{/ts}{/if}
+ {$form.address.$blockId.postal_code.label}
{$form.address.$blockId.postal_code.html}   {if !empty($form.address.$blockId.postal_code_suffix)} + + {$form.address.$blockId.postal_code_suffix.label}
{$form.address.$blockId.postal_code_suffix.html} {help id="id-postal-code-suffix" file="CRM/Contact/Form/Contact.hlp"} + {/if} {/if} diff --git a/xml/schema/Core/Address.xml b/xml/schema/Core/Address.xml index cc6af4895b..d23de1c155 100644 --- a/xml/schema/Core/Address.xml +++ b/xml/schema/Core/Address.xml @@ -60,6 +60,9 @@ 0 Is this the primary address. 2.0 + + CheckBox + index_is_primary @@ -73,6 +76,9 @@ 0 Is this the billing address. 2.0 + + CheckBox + index_is_billing @@ -92,6 +98,9 @@ delivery, etc.). 1.1 + + Text + street_number @@ -100,6 +109,9 @@ true Numeric portion of address number on the street, e.g. For 112A Main St, the street_number = 112. 1.1 + + Text + street_number_suffix @@ -110,6 +122,9 @@ Non-numeric portion of address number on the street, e.g. For 112A Main St, the street_number_suffix = A 1.1 + + Text + street_number_predirectional @@ -118,6 +133,9 @@ 8 Directional prefix, e.g. SE Main St, SE is the prefix. 1.1 + + Text + street_name @@ -127,6 +145,9 @@ true Actual street name, excluding St, Dr, Rd, Ave, e.g. For 112 Main St, the street_name = Main. 1.1 + + Text + index_street_name @@ -140,6 +161,9 @@ 8 St, Rd, Dr, etc. 1.1 + + Text + street_number_postdirectional @@ -148,6 +172,9 @@ 8 Directional prefix, e.g. Main St S, S is the suffix. 1.1 + + Text + street_unit @@ -157,6 +184,9 @@ true Secondary unit designator, e.g. Apt 3 or Unit # 14, or Bldg 1200 1.1 + + Text + supplemental_address_1 @@ -168,6 +198,9 @@ /unit|ap(ar)?t(ment)?\s(\d|\w)+/i Supplemental Address Information, Line 1 1.1 + + Text + supplemental_address_2 @@ -179,6 +212,9 @@ /unit|ap(ar)?t(ment)?\s(\d|\w)+/i Supplemental Address Information, Line 2 1.1 + + Text + supplemental_address_3 @@ -187,6 +223,9 @@ 96 Supplemental Address Information, Line 3 1.1 + + Text + city @@ -198,6 +237,9 @@ /^[A-Za-z]+(\.?)(\s?[A-Za-z]+){0,2}$/ City, Town or Village Name. 1.1 + + Text + index_city @@ -258,7 +300,7 @@ postal_code_suffix - Postal Code Suffix + Zip / Postal Code Suffix varchar 12 true @@ -266,10 +308,13 @@ /\d?\d{4}(-\d{4})?/ Store the suffix, like the +4 part in the USPS system. 1.1 + + Text + postal_code - Postal Code + Zip / Postal Code varchar 12 true @@ -279,6 +324,9 @@ validation. 1.1 + + Text + usps_adc @@ -322,6 +370,10 @@ /geo/i Latitude 1.1 + + Text + 9 + geo_code_2 @@ -331,6 +383,10 @@ true /geo/i 1.1 + + Text + 9 + manual_geo_code @@ -339,6 +395,9 @@ 0 Is this a manually entered geo code 4.3 + + CheckBox + timezone @@ -347,6 +406,9 @@ 8 Timezone expressed as a UTC offset - e.g. United States CST would be written as "UTC-6". 1.1 + + Text + name @@ -358,6 +420,9 @@ /^location|(l(ocation\s)?name)$/i /^\w+$/ 2.1 + + Text + master_id -- 2.25.1