Merge pull request #14536 from civicrm/5.15
[civicrm-core.git] / CRM / Friend / Form.php
index 459384ca45346caca661dbe292c34e5c1cdc1255..4509acd993377f7c524565a73b6d7279d99d51d2 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  * $Id$
  *
  */
@@ -80,14 +80,14 @@ class CRM_Friend_Form extends CRM_Core_Form {
 
     $pcomponent = CRM_Utils_Request::retrieve('pcomponent', 'String', $this, TRUE);
 
-    if (in_array($pcomponent, array(
+    if (in_array($pcomponent, [
       'contribute',
       'event',
-    ))) {
-      $values = array();
-      $params = array('id' => $this->_entityId);
+    ])) {
+      $values = [];
+      $params = ['id' => $this->_entityId];
       CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage',
-        $params, $values, array('title', 'campaign_id', 'is_share')
+        $params, $values, ['title', 'campaign_id', 'is_share']
       );
       $this->_title = CRM_Utils_Array::value('title', $values);
       $this->_campaignId = CRM_Utils_Array::value('campaign_id', $values);
@@ -106,10 +106,10 @@ class CRM_Friend_Form extends CRM_Core_Form {
     elseif ($pcomponent == 'pcp') {
       $this->_pcpBlockId = CRM_Utils_Request::retrieve('blockId', 'Positive', $this, TRUE);
 
-      $values = array();
-      $params = array('id' => $this->_pcpBlockId);
+      $values = [];
+      $params = ['id' => $this->_pcpBlockId];
       CRM_Core_DAO::commonRetrieve('CRM_PCP_DAO_PCPBlock',
-        $params, $values, array('is_tellfriend_enabled', 'tellfriend_limit')
+        $params, $values, ['is_tellfriend_enabled', 'tellfriend_limit']
       );
 
       if (empty($values['is_tellfriend_enabled'])) {
@@ -125,11 +125,10 @@ class CRM_Friend_Form extends CRM_Core_Form {
   FROM  civicrm_pcp pcp
     INNER JOIN  civicrm_contribution_page contrib ON ( pcp.page_id = contrib.id AND pcp.page_type = "contribute" )
   WHERE  pcp.id = %1';
-      $pcp = CRM_Core_DAO::executeQuery($sql, array(1 => array($this->_entityId, 'Positive')));
+      $pcp = CRM_Core_DAO::executeQuery($sql, [1 => [$this->_entityId, 'Positive']]);
       while ($pcp->fetch()) {
         $this->_title = $pcp->title;
         $this->_campaignId = $pcp->campaign_id;
-        $pcp->free();
       }
 
       $this->assign('pcpTitle', $this->_title);
@@ -160,7 +159,7 @@ class CRM_Friend_Form extends CRM_Core_Form {
    * @return void
    */
   public function setDefaultValues() {
-    $defaults = array();
+    $defaults = [];
 
     $defaults['entity_id'] = $this->_entityId;
     $defaults['entity_table'] = $this->_entityTable;
@@ -205,7 +204,7 @@ class CRM_Friend_Form extends CRM_Core_Form {
     $email->freeze();
 
     $this->add('wysiwyg', 'suggested_message', ts('Your Message'), CRM_Core_DAO::getAttribute('CRM_Friend_DAO_Friend', 'suggested_message'));
-    $friend = array();
+    $friend = [];
     $mailLimit = self::NUM_OPTION;
     if ($this->_entityTable == 'civicrm_pcp') {
       $mailLimit = $this->_mailLimit;
@@ -218,21 +217,20 @@ class CRM_Friend_Form extends CRM_Core_Form {
       $this->addRule("friend[$i][email]", ts('The format of this email address is not valid.'), 'email');
     }
 
-    $this->addButtons(array(
-        array(
-          'type' => 'submit',
-          'name' => ts('Send Your Message'),
-          'spacing' => '         ',
-          'isDefault' => TRUE,
-        ),
-        array(
-          'type' => 'cancel',
-          'name' => ts('Cancel'),
-        ),
-      )
-    );
-
-    $this->addFormRule(array('CRM_Friend_Form', 'formRule'));
+    $this->addButtons([
+      [
+        'type' => 'submit',
+        'name' => ts('Send Your Message'),
+        'spacing' => '         ',
+        'isDefault' => TRUE,
+      ],
+      [
+        'type' => 'cancel',
+        'name' => ts('Cancel'),
+      ],
+    ]);
+
+    $this->addFormRule(['CRM_Friend_Form', 'formRule']);
   }
 
   /**
@@ -245,7 +243,7 @@ class CRM_Friend_Form extends CRM_Core_Form {
    */
   public static function formRule($fields) {
 
-    $errors = array();
+    $errors = [];
 
     $valid = FALSE;
     foreach ($fields['friend'] as $key => $val) {
@@ -293,7 +291,7 @@ class CRM_Friend_Form extends CRM_Core_Form {
     CRM_Friend_BAO_Friend::create($formValues);
 
     $this->assign('status', 'thankyou');
-    $defaults = array();
+    $defaults = [];
 
     $defaults['entity_id'] = $this->_entityId;
     $defaults['entity_table'] = $this->_entityTable;