move to static call as per comment from Jitendra and re run regen.sh
[civicrm-core.git] / CRM / Admin / Form / Options.php
index 48afac6a203e2b386afd2b4b8d54068dcd14d47e..e386f1870e26cd56d368f3de2d4ff81bcd83c213 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
+ | Copyright CiviCRM LLC (c) 2004-2016                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2015
- * $Id$
- *
+ * @copyright CiviCRM LLC (c) 2004-2016
  */
 
 /**
- * This class generates form components for Options
- *
+ * This class generates form components for Options.
  */
 class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
@@ -55,8 +52,6 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
   /**
    * Pre-process
-   *
-   * @return void
    */
   public function preProcess() {
     parent::preProcess();
@@ -115,8 +110,6 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
   /**
    * Set default values for the form.
-   *
-   * @return void
    */
   public function setDefaultValues() {
     $defaults = parent::setDefaultValues();
@@ -146,8 +139,6 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
   /**
    * Build the form object.
-   *
-   * @return void
    */
   public function buildQuickForm() {
     parent::buildQuickForm();
@@ -385,14 +376,37 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       }
     }
 
+    $optionGroup = self::getOptionGroupDataType($self->_gName);
+    if ($dataType) {
+      $validate = CRM_Utils_Type::validate($fields['value'], $dataType, FALSE);
+      if (!$validate) {
+        CRM_Core_Session::setStatus(
+          ts('Data Type of the value field for this option value does not match ' . $dataType),
+          ts('Value field Data Type mismatch'));
+      }
+    }
     return $errors;
   }
 
   /**
-   * Process the form submission.
+   * Get the DataType for a specified Option Group.
    *
+   * @param string $optionGroupName name of the option group
    *
-   * @return void
+   * @return string|null
+   */
+  public static function getOptionGroupDataType($optionGroupName) {
+    $optionGroup = civicrm_api3('OptionGroup', 'get', array(
+      'sequential' => 1,
+      'name' => $optionGroupName,
+    ));
+
+    $dataType = CRM_Core_BAO_OptionGroup::getDataType($optionGroup['id']);
+    return $dataType;
+  }
+
+  /**
+   * Process the form submission.
    */
   public function postProcess() {
     if ($this->_action & CRM_Core_Action::DELETE) {