Move greeting params retrieval to the place in the code where it is used
[civicrm-core.git] / CRM / Export / Form / Select.php
index 34a06734bd8599c299af40501d983de44ce05cda..315c622cb146d3c824729b10c0686e393204b2f5 100644 (file)
@@ -91,11 +91,11 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task {
 
     $this->_selectAll = FALSE;
     $this->_exportMode = self::CONTACT_EXPORT;
-    $this->_componentIds = array();
+    $this->_componentIds = [];
     $this->_componentClause = NULL;
 
     // we need to determine component export
-    $components = array('Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity');
+    $components = ['Contact', 'Contribute', 'Member', 'Event', 'Pledge', 'Case', 'Grant', 'Activity'];
 
     // FIXME: This should use a modified version of CRM_Contact_Form_Search::getModeValue but it doesn't have all the contexts
     // FIXME: Or better still, use CRM_Core_DAO_AllCoreTables::getBriefName($daoName) to get the $entityShortName
@@ -140,9 +140,10 @@ class CRM_Export_Form_Select extends CRM_Core_Form_Task {
         $formName = CRM_Utils_System::getClassName($this->controller->getStateMachine());
         $componentName = explode('_', $formName);
         if ($formName == 'CRM_Export_StateMachine_Standalone') {
-          $componentName = array('CRM', $this->controller->get('entity'));
+          $componentName = ['CRM', $this->controller->get('entity')];
         }
-        $entityShortname = $componentName[1]; // Contact
+        // Contact
+        $entityShortname = $componentName[1];
         $entityDAOName = $entityShortname;
         break;
     }
@@ -245,37 +246,37 @@ FROM   {$this->_componentTable}
    */
   public function buildQuickForm() {
     //export option
-    $exportOptions = $mergeOptions = $postalMailing = array();
+    $exportOptions = $mergeOptions = $postalMailing = [];
     $exportOptions[] = $this->createElement('radio',
       NULL, NULL,
       ts('Export PRIMARY fields'),
       self::EXPORT_ALL,
-      array('onClick' => 'showMappingOption( );')
+      ['onClick' => 'showMappingOption( );']
     );
     $exportOptions[] = $this->createElement('radio',
       NULL, NULL,
       ts('Select fields for export'),
       self::EXPORT_SELECTED,
-      array('onClick' => 'showMappingOption( );')
+      ['onClick' => 'showMappingOption( );']
     );
 
     $mergeOptions[] = $this->createElement('radio',
       NULL, NULL,
       ts('Do not merge'),
       self::EXPORT_MERGE_DO_NOT_MERGE,
-      array('onclick' => 'showGreetingOptions( );')
+      ['onclick' => 'showGreetingOptions( );']
     );
     $mergeOptions[] = $this->createElement('radio',
       NULL, NULL,
       ts('Merge All Contacts with the Same Address'),
       self::EXPORT_MERGE_SAME_ADDRESS,
-      array('onclick' => 'showGreetingOptions( );')
+      ['onclick' => 'showGreetingOptions( );']
     );
     $mergeOptions[] = $this->createElement('radio',
       NULL, NULL,
       ts('Merge Household Members into their Households'),
       self::EXPORT_MERGE_HOUSEHOLD,
-      array('onclick' => 'showGreetingOptions( );')
+      ['onclick' => 'showGreetingOptions( );']
     );
 
     $postalMailing[] = $this->createElement('advcheckbox',
@@ -290,9 +291,9 @@ FROM   {$this->_componentTable}
       $this->_greetingOptions = self::getGreetingOptions();
 
       foreach ($this->_greetingOptions as $key => $value) {
-        $fieldLabel = ts('%1 (merging > 2 contacts)', array(1 => ucwords(str_replace('_', ' ', $key))));
+        $fieldLabel = ts('%1 (merging > 2 contacts)', [1 => ucwords(str_replace('_', ' ', $key))]);
         $this->addElement('select', $key, $fieldLabel,
-          $value, array('onchange' => "showOther(this);")
+          $value, ['onchange' => "showOther(this);"]
         );
         $this->addElement('text', "{$key}_other", '');
       }
@@ -303,33 +304,32 @@ FROM   {$this->_componentTable}
       $this->addGroup($postalMailing, 'postal_mailing_export', ts('Postal Mailing Export'), '<br/>');
 
       $this->addElement('select', 'additional_group', ts('Additional Group for Export'),
-        array('' => ts('- select group -')) + CRM_Core_PseudoConstant::nestedGroup(),
-        array('class' => 'crm-select2 huge')
+        ['' => ts('- select group -')] + CRM_Core_PseudoConstant::nestedGroup(),
+        ['class' => 'crm-select2 huge']
       );
     }
 
     $this->buildMapping();
 
-    $this->setDefaults(array(
+    $this->setDefaults([
       'exportOption' => self::EXPORT_ALL,
       'mergeOption' => self::EXPORT_MERGE_DO_NOT_MERGE,
-    ));
-
-    $this->addButtons(array(
-        array(
-          'type' => 'next',
-          'name' => ts('Continue'),
-          'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-          'isDefault' => TRUE,
-        ),
-        array(
-          'type' => 'cancel',
-          'name' => ts('Cancel'),
-        ),
-      )
-    );
-
-    $this->addFormRule(array('CRM_Export_Form_Select', 'formRule'), $this);
+    ]);
+
+    $this->addButtons([
+      [
+        'type' => 'next',
+        'name' => ts('Continue'),
+        'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+        'isDefault' => TRUE,
+      ],
+      [
+        'type' => 'cancel',
+        'name' => ts('Cancel'),
+      ],
+    ]);
+
+    $this->addFormRule(['CRM_Export_Form_Select', 'formRule'], $this);
   }
 
   /**
@@ -345,15 +345,15 @@ FROM   {$this->_componentTable}
    *   mixed true or array of errors
    */
   public static function formRule($params, $files, $self) {
-    $errors = array();
+    $errors = [];
 
     if (CRM_Utils_Array::value('mergeOption', $params) == self::EXPORT_MERGE_SAME_ADDRESS &&
       $self->_matchingContacts
     ) {
-      $greetings = array(
+      $greetings = [
         'postal_greeting' => 'postal_greeting_other',
         'addressee' => 'addressee_other',
-      );
+      ];
 
       foreach ($greetings as $key => $value) {
         $otherOption = CRM_Utils_Array::value($key, $params);
@@ -361,7 +361,7 @@ FROM   {$this->_componentTable}
         if ((CRM_Utils_Array::value($otherOption, $self->_greetingOptions[$key]) == ts('Other')) && empty($params[$value])) {
 
           $label = ucwords(str_replace('_', ' ', $key));
-          $errors[$value] = ts('Please enter a value for %1 (merging > 2 contacts), or select a pre-configured option from the list.', array(1 => $label));
+          $errors[$value] = ts('Please enter a value for %1 (merging > 2 contacts), or select a pre-configured option from the list.', [1 => $label]);
         }
       }
     }
@@ -388,22 +388,6 @@ FROM   {$this->_componentTable}
     // all submitted options or any other argument
     $exportParams = $params;
 
-    if (!empty($this->_greetingOptions)) {
-      foreach ($this->_greetingOptions as $key => $value) {
-        if ($option = CRM_Utils_Array::value($key, $exportParams)) {
-          if ($this->_greetingOptions[$key][$option] == ts('Other')) {
-            $exportParams[$key] = $exportParams["{$key}_other"];
-          }
-          elseif ($this->_greetingOptions[$key][$option] == ts('List of names')) {
-            $exportParams[$key] = '';
-          }
-          else {
-            $exportParams[$key] = $this->_greetingOptions[$key][$option];
-          }
-        }
-      }
-    }
-
     $mappingId = CRM_Utils_Array::value('mapping', $params);
     if ($mappingId) {
       $this->set('mappingId', $mappingId);
@@ -484,7 +468,7 @@ FROM   {$this->_componentTable}
 
     $mappings = CRM_Core_BAO_Mapping::getMappings($exportType);
     if (!empty($mappings)) {
-      $this->add('select', 'mapping', ts('Use Saved Field Mapping'), array('' => '-select-') + $mappings);
+      $this->add('select', 'mapping', ts('Use Saved Field Mapping'), ['' => '-select-'] + $mappings);
     }
   }
 
@@ -492,22 +476,22 @@ FROM   {$this->_componentTable}
    * @return array
    */
   public static function getGreetingOptions() {
-    $options = array();
-    $greetings = array(
+    $options = [];
+    $greetings = [
       'postal_greeting' => 'postal_greeting_other',
       'addressee' => 'addressee_other',
-    );
+    ];
 
     foreach ($greetings as $key => $value) {
-      $params = array();
+      $params = [];
       $optionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name');
 
       CRM_Core_DAO::commonRetrieveAll('CRM_Core_DAO_OptionValue', 'option_group_id', $optionGroupId,
-        $params, array('label', 'filter')
+        $params, ['label', 'filter']
       );
 
       $greetingCount = 1;
-      $options[$key] = array("$greetingCount" => ts('List of names'));
+      $options[$key] = ["$greetingCount" => ts('List of names')];
 
       foreach ($params as $id => $field) {
         if (CRM_Utils_Array::value('filter', $field) == 4) {