CRM-16360 - Don't show id field when creating/editing activity types
[civicrm-core.git] / CRM / Admin / Form / Options.php
index 881fd8931e2a6a044baaa24125f049d3ce743cfe..0a1925082592db984d2ccde0f3f7a48afdac9ec9 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -40,7 +40,7 @@
 class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
   /**
-   * The option group name
+   * The option group name.
    *
    * @var array
    */
@@ -115,17 +115,18 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
 
   /**
    * Set default values for the form.
-   * the default values are retrieved from the database
-   *
    *
    * @return void
    */
   public function setDefaultValues() {
     $defaults = parent::setDefaultValues();
 
-    if (!isset($defaults['weight']) || !$defaults['weight']) {
-      $fieldValues = array('option_group_id' => $this->_gid);
-      $defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues);
+    // Default weight & value
+    $fieldValues = array('option_group_id' => $this->_gid);
+    foreach (array('weight', 'value') as $field) {
+      if (empty($defaults[$field])) {
+        $defaults[$field] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues, $field);
+      }
     }
 
     //setDefault of contact types for email greeting, postal greeting, addressee, CRM-4575
@@ -144,7 +145,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
   }
 
   /**
-   * Build the form object
+   * Build the form object.
    *
    * @return void
    */
@@ -170,6 +171,15 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       TRUE
     );
 
+    if ($this->_gName != 'activity_type') {
+      $this->add('text',
+        'value',
+        ts('Value'),
+        CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'),
+        TRUE
+      );
+    }
+
     if (!in_array($this->_gName, array(
         'email_greeting',
         'postal_greeting',
@@ -214,12 +224,6 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
       $required = TRUE;
     }
     elseif ($this->_gName == 'redaction_rule' || $this->_gName == 'engagement_index') {
-      $this->add('text',
-        'value',
-        ts('Value'),
-        CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'),
-        TRUE
-      );
       if ($this->_gName == 'redaction_rule') {
         $this->add('checkbox',
           'filter',
@@ -331,7 +335,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
   }
 
   /**
-   * Global form rule
+   * Global form rule.
    *
    * @param array $fields
    *   The input form values.
@@ -385,7 +389,7 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
   }
 
   /**
-   * Process the form submission
+   * Process the form submission.
    *
    *
    * @return void