move to static call as per comment from Jitendra and re run regen.sh
[civicrm-core.git] / CRM / Admin / Form / Options.php
index 25db9ff2737b6774611939302fd29dfb2776a749..e386f1870e26cd56d368f3de2d4ff81bcd83c213 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
  */
 
 /**
@@ -376,9 +376,35 @@ 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;
   }
 
+  /**
+   * Get the DataType for a specified Option Group.
+   *
+   * @param string $optionGroupName name of the option group
+   *
+   * @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.
    */