Commit | Line | Data |
---|---|---|
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 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
21 | * This class is to build the form for deleting a field | |
22 | */ | |
23 | class CRM_Custom_Form_DeleteField extends CRM_Core_Form { | |
24 | ||
25 | /** | |
fe482240 | 26 | * The group id. |
6a488035 TO |
27 | * |
28 | * @var int | |
29 | */ | |
30 | protected $_id; | |
31 | ||
32 | /** | |
fe482240 | 33 | * The title of the group being deleted. |
6a488035 TO |
34 | * |
35 | * @var string | |
36 | */ | |
37 | protected $_title; | |
38 | ||
39 | /** | |
fe482240 | 40 | * Set up variables to build the form. |
6a488035 | 41 | * |
6a488035 | 42 | * @return void |
b44e3f84 | 43 | * @access protected |
8ef12e64 | 44 | */ |
00be9182 | 45 | public function preProcess() { |
6a488035 TO |
46 | $this->_id = $this->get('id'); |
47 | ||
be2fb01f CW |
48 | $defaults = []; |
49 | $params = ['id' => $this->_id]; | |
6a488035 TO |
50 | CRM_Core_BAO_CustomField::retrieve($params, $defaults); |
51 | ||
52 | $this->_title = CRM_Utils_Array::value('label', $defaults); | |
5238aa83 | 53 | $this->assign('title', $this->_title); |
be2fb01f | 54 | CRM_Utils_System::setTitle(ts('Delete %1', [1 => $this->_title])); |
6a488035 TO |
55 | } |
56 | ||
57 | /** | |
fe482240 | 58 | * Build the form object. |
6a488035 | 59 | * |
6a488035 | 60 | * @return void |
6a488035 TO |
61 | */ |
62 | public function buildQuickForm() { | |
63 | ||
be2fb01f | 64 | $this->addButtons([ |
518fa0ee SL |
65 | [ |
66 | 'type' => 'next', | |
67 | 'name' => ts('Delete Custom Field'), | |
68 | 'isDefault' => TRUE, | |
69 | ], | |
70 | [ | |
71 | 'type' => 'cancel', | |
72 | 'name' => ts('Cancel'), | |
73 | ], | |
74 | ]); | |
6a488035 TO |
75 | } |
76 | ||
77 | /** | |
fe482240 | 78 | * Process the form when submitted. |
6a488035 | 79 | * |
6a488035 | 80 | * @return void |
6a488035 TO |
81 | */ |
82 | public function postProcess() { | |
83 | $field = new CRM_Core_DAO_CustomField(); | |
84 | $field->id = $this->_id; | |
85 | $field->find(TRUE); | |
86 | ||
87 | CRM_Core_BAO_CustomField::deleteField($field); | |
88 | ||
89 | // also delete any profiles associted with this custom field | |
be2fb01f | 90 | CRM_Core_Session::setStatus(ts('The custom field \'%1\' has been deleted.', [1 => $field->label]), '', 'success'); |
6a488035 TO |
91 | |
92 | } | |
96025800 | 93 | |
6a488035 | 94 | } |