4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
22 namespace Civi\Api4\Generic
;
25 * Create a new object from supplied values.
27 * This function will create 1 new object. It cannot be used to update existing objects. Use the Update or Replace actions for that.
29 class DAOCreateAction
extends AbstractCreateAction
{
30 use Traits\DAOActionTrait
;
35 public function _run(Result
$result) {
36 $this->validateValues();
37 $params = $this->values
;
38 $this->fillDefaults($params);
40 $resultArray = $this->writeObjects([$params]);
42 $result->exchangeArray($resultArray);
46 * @throws \API_Exception
48 protected function validateValues() {
49 if (!empty($this->values
['id'])) {
50 throw new \
API_Exception('Cannot pass id to Create action. Use Update action instead.');
52 parent
::validateValues();