3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Parent class for inline contact forms.
21 abstract class CRM_Contact_Form_Inline
extends CRM_Core_Form
{
24 * Id of the contact that is being edited
30 * Type of contact being edited
36 * Sub type of contact being edited
39 public $_contactSubType;
42 * Explicitly declare the form context.
44 public function getDefaultContext() {
49 * Explicitly declare the entity api name.
51 public function getDefaultEntity() {
56 * Common preprocess: fetch contact ID and contact type
58 public function preProcess() {
59 $this->_contactId
= CRM_Utils_Request
::retrieve('cid', 'Positive', $this, TRUE);
60 $this->assign('contactId', $this->_contactId
);
62 // get contact type and subtype
63 if (empty($this->_contactType
)) {
64 $contactTypeInfo = CRM_Contact_BAO_Contact
::getContactTypes($this->_contactId
);
65 $this->_contactType
= $contactTypeInfo[0];
67 // check if subtype is set
68 if (isset($contactTypeInfo[1])) {
69 // unset contact type which is 0th element
70 unset($contactTypeInfo[0]);
71 $this->_contactSubType
= $contactTypeInfo;
75 $this->assign('contactType', $this->_contactType
);
77 $this->setAction(CRM_Core_Action
::UPDATE
);
81 * Common form elements.
83 public function buildQuickForm() {
84 CRM_Contact_Form_Inline_Lock
::buildQuickForm($this, $this->_contactId
);
94 'name' => ts('Cancel'),
97 $this->addButtons($buttons);
101 * Override default cancel action.
103 public function cancelAction() {
104 $response = ['status' => 'cancel'];
105 CRM_Utils_JSON
::output($response);
109 * Set defaults for the form.
113 public function setDefaultValues() {
114 $defaults = $params = [];
115 $params['id'] = $this->_contactId
;
117 CRM_Contact_BAO_Contact
::getValues($params, $defaults);
123 * Add entry to log table.
125 protected function log() {
126 CRM_Core_BAO_Log
::register($this->_contactId
,
133 * Common function for all inline contact edit forms.
135 * Prepares ajaxResponse
137 protected function response() {
138 $this->ajaxResponse
= array_merge(
139 self
::renderFooter($this->_contactId
),
141 CRM_Contact_Form_Inline_Lock
::getResponse($this->_contactId
)
143 // Note: Post hooks will be called by CRM_Core_Form::mainProcess
147 * Render change log footer markup for a contact and supply count.
149 * Needed for refreshing the contact summary screen
152 * @param bool $includeCount
155 public static function renderFooter($cid, $includeCount = TRUE) {
156 // Load change log footer from template.
157 $smarty = CRM_Core_Smarty
::singleton();
158 $smarty->assign('contactId', $cid);
159 $smarty->assign('external_identifier', CRM_Core_DAO
::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'external_identifier'));
160 $smarty->assign('lastModified', CRM_Core_BAO_Log
::lastModified($cid, 'civicrm_contact'));
161 $viewOptions = CRM_Core_BAO_Setting
::valueOptions(CRM_Core_BAO_Setting
::SYSTEM_PREFERENCES_NAME
,
162 'contact_view_options', TRUE
164 $smarty->assign('changeLog', $viewOptions['log']);
165 $ret = ['markup' => $smarty->fetch('CRM/common/contactFooter.tpl')];
167 $ret['count'] = CRM_Contact_BAO_Contact
::getCountComponent('log', $cid);
169 return ['changeLog' => $ret];