Merge pull request #2876 from mepps/participant-image-event-badge
[civicrm-core.git] / CRM / Contact / Form / Edit / Address.php
index 8c2168c5ec7d60236d0ae63dc3af684727cbbfa8..c786bfaab457b3659146a1725ebb9b82aa8cbe50 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -67,18 +67,15 @@ class CRM_Contact_Form_Edit_Address {
 
     $js = array();
     if (!$inlineEdit) {
-      $js = array('onChange' => 'checkLocation( this.id );');
+      $js = array('onChange' => 'checkLocation( this.id );', 'placeholder' => NULL);
     }
 
-    $form->addSelect("address[$blockId][location_type_id]", array('data-api-entity' => 'address', 'class' => 'eight') + $js);
+    //make location type required for inline edit
+    $form->addSelect("address[$blockId][location_type_id]", array('entity' => 'address', 'class' => 'eight') + $js, $inlineEdit);
 
     if (!$inlineEdit) {
       $js = array('id' => 'Address_' . $blockId . '_IsPrimary', 'onClick' => 'singleSelect( this.id );');
     }
-    else {
-      //make location type required for inline edit
-      $form->addRule( "address[$blockId][location_type_id]", ts('%1 is a required field.', array(1 => ts('Location Type'))), 'required');
-    }
 
     $form->addElement(
       'checkbox',
@@ -88,8 +85,8 @@ class CRM_Contact_Form_Edit_Address {
       $js
     );
 
-    if ( !$inlineEdit ) {
-    $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
+    if (!$inlineEdit) {
+      $js = array('id' => 'Address_' . $blockId . '_IsBilling', 'onClick' => 'singleSelect( this.id );');
     }
 
     $form->addElement(
@@ -172,7 +169,7 @@ class CRM_Contact_Form_Edit_Address {
               $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::countyForState($form->getSubmitValue("address[{$blockId}][state_province_id]"));
             }
             elseif ($form->getSubmitValue("address[{$blockId}][county_id]")) {
-              $selectOptions = array('' => ts('- select a state -')) + CRM_Core_PseudoConstant::county();
+              $selectOptions = array('' => ts('- select -')) + CRM_Core_PseudoConstant::county();
             }
             else {
               $selectOptions = array('' => ts('- select a state -'));
@@ -288,22 +285,21 @@ class CRM_Contact_Form_Edit_Address {
       // shared address
       $form->addElement('checkbox', "address[$blockId][use_shared_address]", NULL, ts('Use another contact\'s address'));
 
-      // get the reserved for address
-      $profileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'shared_address', 'id', 'name');
-
-      if (!$profileId) {
-        CRM_Core_Error::fatal(ts('Your install is missing required "Shared Address" profile.'));
-      }
-
-      CRM_Contact_Form_NewContact::buildQuickForm($form, $blockId, array($profileId));
+      // Override the default profile links to add address form
+      $profileLinks = CRM_Core_BAO_UFGroup::getCreateLinks(array('new_individual', 'new_organization', 'new_household'), 'shared_address');
+      $form->addEntityRef("address[$blockId][master_contact_id]", ts('Share With'), array('create' => $profileLinks));
     }
   }
 
   /**
    * check for correct state / country mapping.
    *
-   * @param array reference $fields - submitted form values.
-   * @param array reference $errors - if any errors found add to this array. please.
+   * @param $fields
+   * @param $files
+   * @param $self
+   *
+   * @internal param \reference $array $fields - submitted form values.
+   * @internal param \reference $array $errors - if any errors found add to this array. please.
    *
    * @return true if no errors
    *         array of errors if any present.