3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
35 * Parent class for inline contact forms.
37 abstract class CRM_Contact_Form_Inline
extends CRM_Core_Form
{
40 * Id of the contact that is being edited
46 * Type of contact being edited
52 * Sub type of contact being edited
55 public $_contactSubType;
58 * Explicitly declare the form context.
60 public function getDefaultContext() {
65 * Explicitly declare the entity api name.
67 public function getDefaultEntity() {
72 * Common preprocess: fetch contact ID and contact type
74 public function preProcess() {
75 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST);
76 $this->assign('contactId', $this->_contactId
);
78 // get contact type and subtype
79 if (empty($this->_contactType
)) {
80 $contactTypeInfo = CRM_Contact_BAO_Contact
::getContactTypes($this->_contactId
);
81 $this->_contactType
= $contactTypeInfo[0];
83 // check if subtype is set
84 if (isset($contactTypeInfo[1])) {
85 // unset contact type which is 0th element
86 unset($contactTypeInfo[0]);
87 $this->_contactSubType
= $contactTypeInfo;
91 $this->assign('contactType', $this->_contactType
);
93 $this->setAction(CRM_Core_Action
::UPDATE
);
97 * Common form elements.
99 public function buildQuickForm() {
100 CRM_Contact_Form_Inline_Lock
::buildQuickForm($this, $this->_contactId
);
105 'name' => ts('Save'),
110 'name' => ts('Cancel'),
113 $this->addButtons($buttons);
117 * Override default cancel action.
119 public function cancelAction() {
120 $response = ['status' => 'cancel'];
121 CRM_Utils_JSON
::output($response);
125 * Set defaults for the form.
129 public function setDefaultValues() {
130 $defaults = $params = [];
131 $params['id'] = $this->_contactId
;
133 CRM_Contact_BAO_Contact
::getValues($params, $defaults);
139 * Add entry to log table.
141 protected function log() {
142 CRM_Core_BAO_Log
::register($this->_contactId
,
149 * Common function for all inline contact edit forms.
151 * Prepares ajaxResponse
153 protected function response() {
154 $this->ajaxResponse
= array_merge(
155 self
::renderFooter($this->_contactId
),
157 CRM_Contact_Form_Inline_Lock
::getResponse($this->_contactId
)
159 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
163 * Render change log footer markup for a contact and supply count.
165 * Needed for refreshing the contact summary screen
168 * @param bool $includeCount
171 public static function renderFooter($cid, $includeCount = TRUE) {
172 // Load change log footer from template.
173 $smarty = CRM_Core_Smarty
::singleton();
174 $smarty->assign('contactId', $cid);
175 $smarty->assign('external_identifier', CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
176 $smarty->assign('lastModified', CRM_Core_BAO_Log
::lastModified($cid, 'civicrm_contact'));
177 $viewOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
178 'contact_view_options', TRUE
180 $smarty->assign('changeLog', $viewOptions['log']);
181 $ret = ['markup' => $smarty->fetch('CRM/common/contactFooter.tpl')];
183 $ret['count'] = CRM_Contact_BAO_Contact
::getCountComponent('log', $cid);
185 return ['changeLog' => $ret];