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 * Form helper class for an OpenID object.
21 class CRM_Contact_Form_Inline_OpenID
extends CRM_Contact_Form_Inline
{
24 * Ims of the contact that is been viewed.
27 private $_openids = [];
30 * No of openid blocks for inline edit.
33 private $_blockCount = 6;
38 public function preProcess() {
41 //get all the existing openids
42 $openid = new CRM_Core_BAO_OpenID();
43 $openid->contact_id
= $this->_contactId
;
45 $this->_openids
= CRM_Core_BAO_Block
::retrieveBlock($openid, NULL);
49 * Build the form object elements for openID object.
51 public function buildQuickForm() {
52 parent
::buildQuickForm();
54 $totalBlocks = $this->_blockCount
;
55 $actualBlockCount = 1;
56 if (count($this->_openids
) > 1) {
57 $actualBlockCount = $totalBlocks = count($this->_openids
);
58 if ($totalBlocks < $this->_blockCount
) {
59 $additionalBlocks = $this->_blockCount
- $totalBlocks;
60 $totalBlocks +
= $additionalBlocks;
68 $this->assign('actualBlockCount', $actualBlockCount);
69 $this->assign('totalBlocks', $totalBlocks);
71 $this->applyFilter('__ALL__', 'trim');
73 for ($blockId = 1; $blockId < $totalBlocks; $blockId++
) {
74 CRM_Contact_Form_Edit_OpenID
::buildQuickForm($this, $blockId, TRUE);
77 $this->addFormRule(['CRM_Contact_Form_Inline_OpenID', 'formRule']);
81 * Global validation rules for the form.
83 * @param array $fields
84 * Posted values of the form.
85 * @param array $errors
86 * List of errors to be posted back to the form.
90 public static function formRule($fields, $errors) {
91 $hasData = $hasPrimary = $errors = [];
92 if (!empty($fields['openid']) && is_array($fields['openid'])) {
93 foreach ($fields['openid'] as $instance => $blockValues) {
94 $dataExists = CRM_Contact_Form_Contact
::blockDataExists($blockValues);
97 $hasData[] = $instance;
98 if (!empty($blockValues['is_primary'])) {
99 $hasPrimary[] = $instance;
100 if (!$primaryID && !empty($blockValues['openid'])) {
101 $primaryID = $blockValues['openid'];
107 if (empty($hasPrimary) && !empty($hasData)) {
108 $errors["openid[1][is_primary]"] = ts('One OpenID should be marked as primary.');
111 if (count($hasPrimary) > 1) {
112 $errors["openid[" . array_pop($hasPrimary) . "][is_primary]"] = ts('Only one OpenID can be marked as primary.');
119 * Set defaults for the form.
123 public function setDefaultValues() {
125 if (!empty($this->_openids
)) {
126 foreach ($this->_openids
as $id => $value) {
127 $defaults['openid'][$id] = $value;
131 // get the default location type
132 $locationType = CRM_Core_BAO_LocationType
::getDefault();
133 $defaults['openid'][1]['location_type_id'] = $locationType->id
;
141 public function postProcess() {
142 $params = $this->exportValues();
144 // Process / save openID
145 $params['contact_id'] = $this->_contactId
;
146 $params['updateBlankLocInfo'] = TRUE;
147 $params['openid']['isIdSet'] = TRUE;
148 foreach ($this->_openids
as $count => $value) {
149 if (!empty($value['id']) && isset($params['openid'][$count])) {
150 $params['openid'][$count]['id'] = $value['id'];
153 CRM_Core_BAO_Block
::create('openid', $params);