Commit | Line | Data |
---|---|---|
19b53e5b C |
1 | <?php |
2 | ||
380f3545 TO |
3 | /* |
4 | +--------------------------------------------------------------------+ | |
41498ac5 | 5 | | Copyright CiviCRM LLC. All rights reserved. | |
380f3545 | 6 | | | |
41498ac5 TO |
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 | | |
380f3545 TO |
10 | +--------------------------------------------------------------------+ |
11 | */ | |
12 | ||
19b53e5b C |
13 | namespace Civi\Api4\Generic; |
14 | ||
15 | /** | |
fc95d9a5 | 16 | * Create a new $ENTITY from supplied values. |
19b53e5b | 17 | * |
fc95d9a5 | 18 | * This action will create 1 new $ENTITY. |
e3c6d5ff | 19 | * It cannot be used to update existing $ENTITIES; use the `Update` or `Replace` actions for that. |
19b53e5b C |
20 | */ |
21 | class DAOCreateAction extends AbstractCreateAction { | |
22 | use Traits\DAOActionTrait; | |
23 | ||
24 | /** | |
25 | * @inheritDoc | |
26 | */ | |
27 | public function _run(Result $result) { | |
961e974c | 28 | $this->formatWriteValues($this->values); |
572b2211 | 29 | $this->fillDefaults($this->values); |
19b53e5b | 30 | $this->validateValues(); |
19b53e5b | 31 | |
572b2211 | 32 | $items = [$this->values]; |
baf63a69 | 33 | $result->exchangeArray($this->writeObjects($items)); |
19b53e5b C |
34 | } |
35 | ||
36 | /** | |
37 | * @throws \API_Exception | |
38 | */ | |
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.'); | |
42 | } | |
43 | parent::validateValues(); | |
44 | } | |
45 | ||
46 | } |