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 +--------------------------------------------------------------------+
13 namespace Civi\Api4\Generic
;
16 * Create a new $ENTITY from supplied values.
18 * This action will create 1 new $ENTITY.
19 * It cannot be used to update existing $ENTITIES; use the `Update` or `Replace` actions for that.
21 class DAOCreateAction
extends AbstractCreateAction
{
22 use Traits\DAOActionTrait
;
27 public function _run(Result
$result) {
28 $this->formatWriteValues($this->values
);
29 $this->fillDefaults($this->values
);
30 $this->validateValues();
32 $items = [$this->values
];
33 $result->exchangeArray($this->writeObjects($items));
37 * @throws \API_Exception
39 protected function validateValues() {
40 if (!empty($this->values
['id'])) {
41 throw new \
API_Exception('Cannot pass id to Create action. Use Update action instead.');
43 parent
::validateValues();