Tag form cleanup
authorColeman Watts <coleman@civicrm.org>
Mon, 19 Dec 2016 18:07:55 +0000 (13:07 -0500)
committerColeman Watts <coleman@civicrm.org>
Fri, 23 Dec 2016 22:09:00 +0000 (17:09 -0500)
CRM/Core/BAO/Tag.php
CRM/Tag/Form/Edit.php

index cc44df7c02e7dcc9795dd8f0dea7727e983febe3..6bc321a8cfcef3bb7e94f0d0c3179d0fa30c3d61 100644 (file)
@@ -346,7 +346,7 @@ class CRM_Core_BAO_Tag extends CRM_Core_DAO_Tag {
   }
 
   /**
-   * Takes an associative array and creates a contact object.
+   * Takes an associative array and creates a tag object.
    *
    * The function extract all the params it needs to initialize the create a
    * contact object. the params array could contain additional unused name/value
index 4e827c0152669c02163dea65ff115764b5a8ddc9..8b60e348fd3437d70c456bddc5ebfb3bfad1d675 100644 (file)
@@ -48,8 +48,6 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
    * Build the form object.
    */
   public function buildQuickForm() {
-    $this->setPageTitle($this->_isTagSet ? ts('Tag Set') : ts('Tag'));
-
     if ($this->_action == CRM_Core_Action::DELETE) {
       if ($this->_id && $tag = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'name', 'parent_id')) {
         $url = CRM_Utils_System::url('civicrm/tag', "reset=1");
@@ -126,8 +124,8 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
         $adminReservedTags = FALSE;
       }
       $this->assign('adminReservedTags', $adminReservedTags);
-
     }
+    $this->setPageTitle($this->_isTagSet ? ts('Tag Set') : ts('Tag'));
     parent::buildQuickForm();
   }
 
@@ -136,6 +134,9 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
     if (empty($this->_id) || !CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $this->_id, 'color')) {
       $defaults['color'] = '#ffffff';
     }
+    if (empty($this->_id) && $this->_isTagSet) {
+      $defaults['used_for'] = 'civicrm_contact';
+    }
     return $defaults;
   }
 
@@ -143,12 +144,12 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
    * Process the form submission.
    */
   public function postProcess() {
-    $params = $ids = array();
-
     // store the submitted values in an array
     $params = $this->exportValues();
+    if ($this->_id) {
+      $params['id'] = $this->_id;
+    }
 
-    $ids['tag'] = $this->_id;
     if ($this->_action == CRM_Core_Action::ADD ||
       $this->_action == CRM_Core_Action::UPDATE
     ) {
@@ -176,12 +177,12 @@ class CRM_Tag_Form_Edit extends CRM_Admin_Form {
       if ($this->_id > 0) {
         $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id));
         CRM_Core_BAO_Tag::del($this->_id);
-        CRM_Core_Session::setStatus(ts('The tag \'%1\' has been deleted.', array(1 => $tag['name'])), ts('Deleted'), 'success');
+        CRM_Core_Session::setStatus(ts("The tag '%1' has been deleted.", array(1 => $tag['name'])), ts('Deleted'), 'success');
       }
     }
     else {
-      $tag = CRM_Core_BAO_Tag::add($params, $ids);
-      CRM_Core_Session::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name)), ts('Saved'), 'success');
+      $tag = CRM_Core_BAO_Tag::add($params);
+      CRM_Core_Session::setStatus(ts("The tag '%1' has been saved.", array(1 => $tag->name)), ts('Saved'), 'success');
     }
   }