DeleteField.php 3.27 KB
Newer Older
totten's avatar
totten committed
1 2 3
<?php
/*
 +--------------------------------------------------------------------+
totten's avatar
totten committed
4
 | CiviCRM version 5                                                  |
totten's avatar
totten committed
5
 +--------------------------------------------------------------------+
yashodha's avatar
yashodha committed
6
 | Copyright CiviCRM LLC (c) 2004-2018                                |
totten's avatar
totten committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 +--------------------------------------------------------------------+
 | This file is a part of CiviCRM.                                    |
 |                                                                    |
 | CiviCRM is free software; you can copy, modify, and distribute it  |
 | under the terms of the GNU Affero General Public License           |
 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
 |                                                                    |
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the GNU Affero General Public License for more details.        |
 |                                                                    |
 | You should have received a copy of the GNU Affero General Public   |
 | License and the CiviCRM Licensing Exception along                  |
 | with this program; if not, contact CiviCRM LLC                     |
 | at info[AT]civicrm[DOT]org. If you have questions about the        |
 | GNU Affero General Public License or the licensing of CiviCRM,     |
 | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
 +--------------------------------------------------------------------+
26
 */
totten's avatar
totten committed
27 28 29 30

/**
 *
 * @package CRM
yashodha's avatar
yashodha committed
31
 * @copyright CiviCRM LLC (c) 2004-2018
totten's avatar
totten committed
32 33 34 35 36 37 38 39 40 41
 * $Id$
 *
 */

/**
 * This class is to build the form for deleting a field
 */
class CRM_Custom_Form_DeleteField extends CRM_Core_Form {

  /**
42
   * The group id.
totten's avatar
totten committed
43 44 45 46 47 48
   *
   * @var int
   */
  protected $_id;

  /**
49
   * The title of the group being deleted.
totten's avatar
totten committed
50 51 52 53 54 55
   *
   * @var string
   */
  protected $_title;

  /**
56
   * Set up variables to build the form.
totten's avatar
totten committed
57 58
   *
   * @return void
Dmitry Smirnov's avatar
Dmitry Smirnov committed
59
   * @access protected
eileen's avatar
eileen committed
60
   */
61
  public function preProcess() {
totten's avatar
totten committed
62 63 64 65 66 67 68
    $this->_id = $this->get('id');

    $defaults = array();
    $params = array('id' => $this->_id);
    CRM_Core_BAO_CustomField::retrieve($params, $defaults);

    $this->_title = CRM_Utils_Array::value('label', $defaults);
69
    $this->assign('title', $this->_title);
70
    CRM_Utils_System::setTitle(ts('Delete %1', array(1 => $this->_title)));
totten's avatar
totten committed
71 72 73
  }

  /**
74
   * Build the form object.
totten's avatar
totten committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
   *
   * @return void
   */
  public function buildQuickForm() {

    $this->addButtons(array(
        array(
          'type' => 'next',
          'name' => ts('Delete Custom Field'),
          'isDefault' => TRUE,
        ),
        array(
          'type' => 'cancel',
          'name' => ts('Cancel'),
        ),
      )
    );
  }

  /**
95
   * Process the form when submitted.
totten's avatar
totten committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109
   *
   * @return void
   */
  public function postProcess() {
    $field = new CRM_Core_DAO_CustomField();
    $field->id = $this->_id;
    $field->find(TRUE);

    CRM_Core_BAO_CustomField::deleteField($field);

    // also delete any profiles associted with this custom field
    CRM_Core_Session::setStatus(ts('The custom field \'%1\' has been deleted.', array(1 => $field->label)), '', 'success');

  }
110

totten's avatar
totten committed
111
}