Merge pull request #20396 from eileenmcnaughton/entry3
[civicrm-core.git] / CRM / Custom / Form / DeleteGroup.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
19 * This class is to build the form for Deleting Group
20 */
21class CRM_Custom_Form_DeleteGroup extends CRM_Core_Form {
22
23 /**
fe482240 24 * The group id.
6a488035
TO
25 *
26 * @var int
27 */
28 protected $_id;
29
30 /**
fe482240 31 * The title of the group being deleted.
6a488035
TO
32 *
33 * @var string
34 */
35 protected $_title;
36
37 /**
fe482240 38 * Set up variables to build the form.
6a488035
TO
39 *
40 * @return void
b44e3f84 41 * @access protected
8ef12e64 42 */
00be9182 43 public function preProcess() {
6a488035
TO
44 $this->_id = $this->get('id');
45
be2fb01f
CW
46 $defaults = [];
47 $params = ['id' => $this->_id];
6a488035
TO
48 CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
49 $this->_title = $defaults['title'];
50
51 //check wheter this contain any custom fields
52 $customField = new CRM_Core_DAO_CustomField();
53 $customField->custom_group_id = $this->_id;
54
55 if ($customField->find(TRUE)) {
be2fb01f 56 CRM_Core_Session::setStatus(ts("The Group '%1' cannot be deleted! You must Delete all custom fields in this group prior to deleting the group.", [1 => $this->_title]), ts('Deletion Error'), 'error');
6a488035
TO
57 $url = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1");
58 CRM_Utils_System::redirect($url);
59 return TRUE;
60 }
61 $this->assign('title', $this->_title);
62
63 CRM_Utils_System::setTitle(ts('Confirm Custom Group Delete'));
64 }
65
66 /**
fe482240 67 * Build the form object.
6a488035 68 *
355ba699 69 * @return void
6a488035
TO
70 */
71 public function buildQuickForm() {
72
be2fb01f 73 $this->addButtons([
518fa0ee
SL
74 [
75 'type' => 'next',
76 'name' => ts('Delete Custom Group'),
77 'isDefault' => TRUE,
78 ],
79 [
80 'type' => 'cancel',
81 'name' => ts('Cancel'),
82 ],
83 ]);
6a488035
TO
84 }
85
86 /**
fe482240 87 * Process the form when submitted.
6a488035
TO
88 *
89 * @return void
6a488035
TO
90 */
91 public function postProcess() {
92 $group = new CRM_Core_DAO_CustomGroup();
93 $group->id = $this->_id;
94 $group->find(TRUE);
95
96 $wt = CRM_Utils_Weight::delWeight('CRM_Core_DAO_CustomGroup', $this->_id);
97 CRM_Core_BAO_CustomGroup::deleteGroup($group);
be2fb01f 98 CRM_Core_Session::setStatus(ts("The Group '%1' has been deleted.", [1 => $group->title]), '', 'success');
6a488035 99 }
96025800 100
6a488035 101}