Merge pull request #4752 from davecivicrm/CRM-15180
[civicrm-core.git] / CRM / Admin / Form / Tag.php
index f1812e8db73fe10ece10ce23db12394dcc05d624..f3dce6a01fd923d20d96bceace486b7b826fdf69 100644 (file)
@@ -41,18 +41,21 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
   protected $_isTagSet;
 
   /**
-   * Function to build the form
+   * Build the form object
    *
    * @return void
    * @access public
    */
   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')) {
-        CRM_Core_Session::setStatus(ts("This tag cannot be deleted. You must delete all its child tags ('%1', etc) prior to deleting this tag.", array(1 => $tag)), ts('Sorry'), 'error');
         $url = CRM_Utils_System::url('civicrm/admin/tag', "reset=1");
-        CRM_Utils_System::redirect($url);
-        return TRUE;
+        CRM_Core_Error::statusBounce(ts("This tag cannot be deleted. You must delete all its child tags ('%1', etc) prior to deleting this tag.", array(1 => $tag)), $url);
+      }
+      if ($this->_values['is_reserved'] == 1 && !CRM_Core_Permission::check('administer reserved tags')) {
+        CRM_Core_Error::statusBounce(ts("You do not have sufficient permission to delete this reserved tag."));
       }
     }
     else {
@@ -65,7 +68,7 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
         $this->_isTagSet = TRUE;
       }
 
-      $allTag = array('' => '- ' . ts('select') . ' -') + CRM_Core_BAO_Tag::getTagsNotInTagset();
+      $allTag = array('' => ts('- select -')) + CRM_Core_BAO_Tag::getTagsNotInTagset();
 
       if ($this->_id) {
         unset($allTag[$this->_id]);
@@ -73,6 +76,14 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
 
       if (!$this->_isTagSet) {
         $this->add('select', 'parent_id', ts('Parent Tag'), $allTag, FALSE, array('class' => 'crm-select2'));
+
+        // Tagsets are not selectable by definition so only include the selectable field if NOT a tagset.
+        $selectable = $this->add('checkbox', 'is_selectable', ts('Selectable?'));
+        // Selectable should be checked by default when creating a new tag
+        if ($this->_action == CRM_Core_Action::ADD) {
+          $selectable->setValue(1);        
+        }
+
       }
 
       $this->assign('isTagSet', $this->_isTagSet);
@@ -88,9 +99,6 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
         CRM_Core_DAO::getAttribute('CRM_Core_DAO_Tag', 'description')
       );
 
-      //@lobo haven't a clue why the checkbox isn't displayed (it should be checked by default
-      $this->add('checkbox', 'is_selectable', ts("If it's a tag or a category"));
-
       $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
 
       $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
@@ -119,7 +127,7 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
   }
 
   /**
-   * Function to process the form
+   * Process the form submission
    *
    * @access public
    *
@@ -147,6 +155,10 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
       $params['is_reserved'] = 0;
     }
 
+    if (!isset($params['is_selectable'])) {
+      $params['is_selectable'] = 0;
+    }
+
     if ($this->_action == CRM_Core_Action::DELETE) {
       if ($this->_id > 0) {
         $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id));
@@ -159,6 +171,6 @@ class CRM_Admin_Form_Tag extends CRM_Admin_Form {
       CRM_Core_Session::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name)), ts('Saved'), 'success');
     }
   }
-  //end of function
+
 }