CRM-19769 - Add color field to tag edit form
authorColeman Watts <coleman@civicrm.org>
Thu, 15 Dec 2016 04:44:26 +0000 (23:44 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 23 Dec 2016 22:06:19 +0000 (17:06 -0500)
CRM/Core/Form.php
CRM/Tag/Form/Edit.php
templates/CRM/Tag/Form/Edit.tpl

index c694a85252345205d610528026756b60f2725887..eb230d457d4065520ebaf28f3d7425255e7c70df 100644 (file)
@@ -217,6 +217,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     'number',
     'url',
     'email',
+    'color',
   );
 
   /**
@@ -345,6 +346,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
     $attributes = '', $required = FALSE, $extra = NULL
   ) {
     // Fudge some extra types that quickform doesn't support
+    $inputType = $type;
     if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
       $attributes = ($attributes ? $attributes : array()) + array('class' => '');
       $attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
@@ -384,6 +386,10 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
       CRM_Core_Error::fatal(HTML_QuickForm::errorMessage($element));
     }
 
+    if ($inputType == 'color') {
+      $this->addRule($name, ts('%1 must contain a color value e.g. #ffffff.', array(1 => $label)), 'regex', '/#[0-9a-fA-F]{6}/');
+    }
+
     if ($required) {
       if ($type == 'file') {
         $error = $this->addRule($name, ts('%1 is a required field.', array(1 => $label)), 'uploadedfile');
index be3b6db482b633f9536ae09dab6b9f70aa9492cc..aa7ab4145773c15a71c2abb83d42a12d2609bfd7 100644 (file)
@@ -85,6 +85,7 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
           $selectable->setValue(1);
         }
 
+        $this->add('color', 'color', ts('Color'));
       }
 
       $this->assign('isTagSet', $this->_isTagSet);
@@ -130,6 +131,12 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
     parent::buildQuickForm();
   }
 
+  public function setDefaultValues() {
+    $defaults = parent::setDefaultValues();
+    $defaults['color'] = '#ffffff';
+    return $defaults;
+  }
+
   /**
    * Process the form submission.
    */
index fa60d2265ac4595e450938bff07cc338d7ee7fbe..4d982a765e485f6831f8319794b90750bacbe8a5 100644 (file)
             </span>
           </td>
         </tr>
+      {if $form.color.html}
+        <tr class="crm-tag-form-block-color">
+          <td class="label">{$form.color.label}</td>
+          <td>{$form.color.html}</td>
+        </tr>
+      {/if}
         <tr class="crm-tag-form-block-is_reserved">
            <td class="label">{$form.is_reserved.label}</td>
            <td>{$form.is_reserved.html} <br /><span class="description">{ts}Reserved tags can not be deleted. Users with 'administer reserved tags' permission can set or unset the reserved flag. You must uncheck 'Reserved' (and delete any child tags) before you can delete a tag.{/ts}