From 1192bd09da2e8e253e9734b1161f38ea59c079e2 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 14 Dec 2016 23:44:26 -0500 Subject: [PATCH] CRM-19769 - Add color field to tag edit form --- CRM/Core/Form.php | 6 ++++++ CRM/Tag/Form/Edit.php | 7 +++++++ templates/CRM/Tag/Form/Edit.tpl | 6 ++++++ 3 files changed, 19 insertions(+) diff --git a/CRM/Core/Form.php b/CRM/Core/Form.php index c694a85252..eb230d457d 100644 --- a/CRM/Core/Form.php +++ b/CRM/Core/Form.php @@ -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'); diff --git a/CRM/Tag/Form/Edit.php b/CRM/Tag/Form/Edit.php index be3b6db482..aa7ab41457 100644 --- a/CRM/Tag/Form/Edit.php +++ b/CRM/Tag/Form/Edit.php @@ -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. */ diff --git a/templates/CRM/Tag/Form/Edit.tpl b/templates/CRM/Tag/Form/Edit.tpl index fa60d2265a..4d982a765e 100644 --- a/templates/CRM/Tag/Form/Edit.tpl +++ b/templates/CRM/Tag/Form/Edit.tpl @@ -52,6 +52,12 @@ + {if $form.color.html} + + {$form.color.label} + {$form.color.html} + + {/if} {$form.is_reserved.label} {$form.is_reserved.html}
{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} -- 2.25.1