Merge pull request #9174 from colemanw/CRM-19448
[civicrm-core.git] / CRM / Price / Form / Set.php
index 9e278f6c41e47858cb03a55ad53946c94c13c74d..90d9be60fd3ce1e5ac5f25b22fd3927acbcb6826 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
@@ -102,6 +102,18 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     if ($asciiValue >= 48 && $asciiValue <= 57) {
       $errors['title'] = ts("Name cannot not start with a digit");
     }
+    // CRM-16189
+    if (!empty($fields['extends'])
+      && (array_key_exists(CRM_Core_Component::getComponentID('CiviEvent'), $fields['extends'])
+        || array_key_exists(CRM_Core_Component::getComponentID('CiviMember'), $fields['extends']))
+    ) {
+      try {
+        CRM_Financial_BAO_FinancialAccount::validateFinancialType($fields['financial_type_id']);
+      }
+      catch (CRM_Core_Exception $e) {
+        $errors['financial_type_id'] = $e->getMessage();
+      }
+    }
     return empty($errors) ? TRUE : $errors;
   }
 
@@ -210,18 +222,17 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
     $this->addElement('checkbox', 'is_active', ts('Is this Price Set active?'));
 
     $this->addButtons(array(
-        array(
-          'type' => 'next',
-          'name' => ts('Save'),
-          'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
-          'isDefault' => TRUE,
-        ),
-        array(
-          'type' => 'cancel',
-          'name' => ts('Cancel'),
-        ),
-      )
-    );
+      array(
+        'type' => 'next',
+        'name' => ts('Save'),
+        'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
+        'isDefault' => TRUE,
+      ),
+      array(
+        'type' => 'cancel',
+        'name' => ts('Cancel'),
+      ),
+    ));
 
     $this->addFormRule(array('CRM_Price_Form_Set', 'formRule'));
 
@@ -292,11 +303,11 @@ class CRM_Price_Form_Set extends CRM_Core_Form {
       // Jump directly to adding a field if popups are disabled
       $action = CRM_Core_Resources::singleton()->ajaxPopupsEnabled ? 'browse' : 'add';
       $url = CRM_Utils_System::url('civicrm/admin/price/field', array(
-          'reset' => 1,
-          'action' => $action,
-          'sid' => $set->id,
-          'new' => 1,
-        ));
+        'reset' => 1,
+        'action' => $action,
+        'sid' => $set->id,
+        'new' => 1,
+      ));
       CRM_Core_Session::setStatus(ts("Your Set '%1' has been added. You can add fields to this set now.",
         array(1 => $set->title)
       ), ts('Saved'), 'success');