-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30140 from colemanw/afformLocBlock
dev/core#5053 Afform - Add support for saving event location
- Loading branch information
Showing
30 changed files
with
671 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Api4\Action\LocBlock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
class Create extends \Civi\Api4\Generic\DAOCreateAction { | ||
use LocBlockSaveTrait; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Api4\Action\LocBlock; | ||
|
||
use Civi\Api4\LocBlock; | ||
use Civi\Api4\Utils\CoreUtil; | ||
|
||
/** | ||
* Code shared by LocBlock create/update/save actions | ||
*/ | ||
trait LocBlockSaveTrait { | ||
|
||
/** | ||
* @param array $items | ||
* @return array | ||
*/ | ||
protected function write(array $items) { | ||
foreach ($items as &$item) { | ||
self::saveLocations($item); | ||
} | ||
$saved = parent::write($items); | ||
return $saved; | ||
} | ||
|
||
/** | ||
* @param array $params | ||
*/ | ||
protected function saveLocations(array &$params) { | ||
if (!empty($params['id'])) { | ||
$locBlock = LocBlock::get(FALSE) | ||
->addWhere('id', '=', $params['id']) | ||
->execute()->first(); | ||
} | ||
foreach (['Address', 'Email', 'Phone', 'IM'] as $joinEntity) { | ||
foreach (['', '_2'] as $suffix) { | ||
$joinField = strtolower($joinEntity) . $suffix . '_id'; | ||
$item = \CRM_Utils_Array::filterByPrefix($params, "$joinField."); | ||
$entityId = $params[$joinField] ?? $locBlock[$joinField] ?? NULL; | ||
if ($item) { | ||
$labelField = CoreUtil::getInfoItem($joinEntity, 'label_field'); | ||
// If NULL was given for the main field (e.g. `email`) then delete the record IF it's not in use | ||
if (!empty($params['id']) && $entityId && $labelField && array_key_exists($labelField, $item) && ($item[$labelField] === NULL || $item[$labelField] === '')) { | ||
$referenceCount = CoreUtil::getRefCountTotal($joinEntity, $entityId); | ||
if ($referenceCount <= 1) { | ||
civicrm_api4($joinEntity, 'delete', [ | ||
'checkPermissions' => FALSE, | ||
'where' => [ | ||
['id', '=', $entityId], | ||
], | ||
]); | ||
} | ||
} | ||
else { | ||
$item['contact_id'] = ''; | ||
if ($entityId) { | ||
$item['id'] = $entityId; | ||
} | ||
$saved = civicrm_api4($joinEntity, 'save', [ | ||
'checkPermissions' => FALSE, | ||
'records' => [$item], | ||
])->first(); | ||
$params[$joinField] = $saved['id'] ?? NULL; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected function resolveFKValues(array &$record): void { | ||
// Override parent function with noop to prevent spurious matching | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Api4\Action\LocBlock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
class Save extends \Civi\Api4\Generic\DAOSaveAction { | ||
use LocBlockSaveTrait; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
namespace Civi\Api4\Action\LocBlock; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
class Update extends \Civi\Api4\Generic\DAOUpdateAction { | ||
use LocBlockSaveTrait; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
return [ | ||
'type' => 'join', | ||
'repeat_max' => 1, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.