Remove use of nullArray in delete hooks
[civicrm-core.git] / CRM / Core / BAO / UFGroup.php
index 88d84f04afa8466f6f9ddab44ca3c82d0585d180..20fd1ca0495287fd353ab38d67ce62aea624900c 100644 (file)
@@ -246,7 +246,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    * and format for use with buildProfile. This is the SQL analog of
    * formatUFFields().
    *
-   * @param mix $id
+   * @param int $id
    *   The id of the UF group or ids of ufgroup.
    * @param bool|int $register are we interested in registration fields
    * @param int $action
@@ -1310,12 +1310,7 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
           if ($htmlType == 'Link') {
             $url = $params[$index];
           }
-          elseif (in_array($htmlType, [
-            'CheckBox',
-            'Multi-Select',
-            'Multi-Select State/Province',
-            'Multi-Select Country',
-          ])) {
+          elseif (!empty($field['serialize'])) {
             $valSeparator = CRM_Core_DAO::VALUE_SEPARATOR;
             $selectedOptions = explode($valSeparator, $params[$index]);
 
@@ -1404,6 +1399,8 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
    *
    */
   public static function del($id) {
+    CRM_Utils_Hook::pre('delete', 'UFGroup', $id);
+
     //check whether this group contains  any profile fields
     $profileField = new CRM_Core_DAO_UFField();
     $profileField->uf_group_id = $id;
@@ -1421,6 +1418,8 @@ class CRM_Core_BAO_UFGroup extends CRM_Core_DAO_UFGroup {
     $group = new CRM_Core_DAO_UFGroup();
     $group->id = $id;
     $group->delete();
+
+    CRM_Utils_Hook::post('delete', 'UFGroup', $id, $group);
     return 1;
   }
 
@@ -1869,7 +1868,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       }
     }
     elseif (substr($fieldName, 0, 7) === 'country') {
-      $form->add('select', $name, $title, ['' => ts('- select -')] + CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
+      $form->add('select', $name, $title, CRM_Core_PseudoConstant::country(), $required, $selectAttributes);
       $config = CRM_Core_Config::singleton();
       if (!in_array($mode, [CRM_Profile_Form::MODE_EDIT, CRM_Profile_Form::MODE_SEARCH]) &&
         $config->defaultContactCountry
@@ -1895,16 +1894,12 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
             $providerName = substr($name, 0, -1) . '-provider_id]';
           }
           $form->add('select', $providerName, NULL,
-            [
-              '' => ts('- select -'),
-            ] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required
+            CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required
           );
         }
         else {
           $form->add('select', $name . '-provider_id', $title,
-            [
-              '' => ts('- select -'),
-            ] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required
+            CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), $required
           );
         }
 
@@ -1916,7 +1911,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     elseif (CRM_Utils_Array::value('name', $field) == 'membership_type') {
       list($orgInfo, $types) = CRM_Member_BAO_MembershipType::getMembershipTypeInfo();
       $sel = &$form->addElement('hierselect', $name, $title);
-      $select = ['' => ts('- select -')];
+      $select = ['' => ts('- select membership type -')];
       if (count($orgInfo) == 1 && $field['is_required']) {
         // we only have one org - so we should default to it. Not sure about defaulting to first type
         // as it could be missed - so adding a select
@@ -1932,9 +1927,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
     elseif (CRM_Utils_Array::value('name', $field) == 'membership_status') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required
+        CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'), $required
       );
     }
     elseif (in_array($fieldName, ['gender_id', 'communication_style_id'])) {
@@ -1999,7 +1992,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         'contact_type' => $profileType,
         'greeting_type' => $fieldName,
       ];
-      $form->add('select', $name, $title, ['' => ts('- select -')] + CRM_Core_PseudoConstant::greeting($greeting), $required);
+      $form->add('select', $name, $title, CRM_Core_PseudoConstant::greeting($greeting), $required, ['placeholder' => TRUE]);
       // add custom greeting element
       $form->add('text', $fieldName . '_custom', ts('Custom %1', [1 => ucwords(str_replace('_', ' ', $fieldName))]),
         NULL, FALSE
@@ -2019,7 +2012,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       $form->add('select', $name, $title, CRM_Core_SelectValues::pmf());
     }
     elseif ($fieldName === 'preferred_language') {
-      $form->add('select', $name, $title, ['' => ts('- select -')] + CRM_Contact_BAO_Contact::buildOptions('preferred_language'), $required);
+      $form->add('select', $name, $title, CRM_Contact_BAO_Contact::buildOptions('preferred_language'), $required, ['placeholder' => TRUE]);
     }
     elseif ($fieldName == 'external_identifier') {
       $form->add('text', $name, $title, $attributes, $required);
@@ -2037,7 +2030,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       CRM_Contact_Form_Edit_TagsAndGroups::buildQuickForm($form, $contactId,
         CRM_Contact_Form_Edit_TagsAndGroups::GROUP,
         TRUE, $required,
-        $title, NULL, $name
+        $title, NULL, $name, 'checkbox', TRUE
       );
     }
     elseif ($fieldName === 'tag') {
@@ -2078,35 +2071,29 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     elseif ($fieldName === 'product_name') {
       list($products, $options) = CRM_Contribute_BAO_Premium::getPremiumProductInfo();
       $sel = &$form->addElement('hierselect', $name, $title);
-      $products = ['0' => ts('- select -')] + $products;
+      $products = ['0' => ts('- select %1 -', [1 => $title])] + $products;
       $sel->setOptions([$products, $options]);
     }
     elseif ($fieldName === 'payment_instrument') {
       $form->add('select', $name, $title,
-        ['' => ts('- select -')] + CRM_Contribute_PseudoConstant::paymentInstrument(), $required);
+        CRM_Contribute_PseudoConstant::paymentInstrument(), $required, ['placeholder' => TRUE]);
     }
     elseif ($fieldName === 'financial_type') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Contribute_PseudoConstant::financialType(), $required
+        CRM_Contribute_PseudoConstant::financialType(), $required, ['placeholder' => TRUE]
       );
     }
     elseif ($fieldName === 'contribution_status_id') {
       $contributionStatuses = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses();
 
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + $contributionStatuses, $required
+        $contributionStatuses, $required, ['placeholder' => TRUE]
       );
     }
     elseif ($fieldName === 'soft_credit_type') {
       $name = "soft_credit_type[$rowNumber]";
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Core_OptionGroup::values("soft_credit_type")
+        CRM_Core_OptionGroup::values("soft_credit_type"), ['placeholder' => TRUE]
       );
       //CRM-15350: choose SCT field default value as 'Gift' for membership use
       //else (for contribution), use configured SCT default value
@@ -2124,23 +2111,20 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
     elseif ($fieldName == 'contribution_page_id') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Contribute_PseudoConstant::contributionPage(), $required, 'class="big"'
+        CRM_Contribute_PseudoConstant::contributionPage(), $required, [
+          'class' => 'big',
+          'placeholder' => TRUE,
+        ]
       );
     }
     elseif ($fieldName == 'activity_status_id') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Core_PseudoConstant::activityStatus(), $required
+        CRM_Core_PseudoConstant::activityStatus(), $required, ['placeholder' => TRUE]
       );
     }
     elseif ($fieldName == 'activity_engagement_level') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Campaign_PseudoConstant::engagementLevel(), $required
+        CRM_Campaign_PseudoConstant::engagementLevel(), $required, ['placeholder' => TRUE]
       );
     }
     elseif ($fieldName == 'participant_status') {
@@ -2149,9 +2133,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
         $cond = 'visibility_id = 1';
       }
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required
+        CRM_Event_PseudoConstant::participantStatus(NULL, $cond, 'label'), $required, ['placeholder' => TRUE]
       );
     }
     elseif ($fieldName == 'participant_role') {
@@ -2160,9 +2142,7 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       }
       else {
         $form->add('select', $name, $title,
-          [
-            '' => ts('- select -'),
-          ] + CRM_Event_PseudoConstant::participantRole(), $required
+          CRM_Event_PseudoConstant::participantRole(), $required, ['placeholder' => TRUE]
         );
       }
     }
@@ -2181,9 +2161,11 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
           $form->_componentCampaigns
         ));
         $form->add('select', $name, $title,
+          $campaigns, $required,
           [
-            '' => ts('- select -'),
-          ] + $campaigns, $required, 'class="crm-select2 big"'
+            'class' => 'crm-select2 big',
+            'placeholder' => TRUE,
+          ]
         );
       }
     }
@@ -2196,10 +2178,8 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
     }
     elseif ($fieldName == 'case_status') {
       $form->add('select', $name, $title,
-        [
-          '' => ts('- select -'),
-        ] + CRM_Case_BAO_Case::buildOptions('case_status_id', 'create'),
-        $required
+        CRM_Case_BAO_Case::buildOptions('case_status_id', 'create'),
+        $required, ['placeholder' => TRUE]
       );
     }
     else {