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 | ||
13 | /** | |
14 | * | |
15 | * @package CRM | |
ca5cec67 | 16 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
380f3545 TO |
17 | * $Id$ |
18 | * | |
19 | */ | |
20 | ||
21 | ||
19b53e5b C |
22 | namespace Civi\Api4\Generic; |
23 | ||
24 | /** | |
fc95d9a5 | 25 | * Create a new $ENTITY from supplied values. |
19b53e5b | 26 | * |
fc95d9a5 | 27 | * This action will create 1 new $ENTITY. |
e3c6d5ff | 28 | * It cannot be used to update existing $ENTITIES; use the `Update` or `Replace` actions for that. |
19b53e5b C |
29 | */ |
30 | class DAOCreateAction extends AbstractCreateAction { | |
31 | use Traits\DAOActionTrait; | |
32 | ||
33 | /** | |
34 | * @inheritDoc | |
35 | */ | |
36 | public function _run(Result $result) { | |
961e974c | 37 | $this->formatWriteValues($this->values); |
19b53e5b C |
38 | $this->validateValues(); |
39 | $params = $this->values; | |
40 | $this->fillDefaults($params); | |
41 | ||
42 | $resultArray = $this->writeObjects([$params]); | |
43 | ||
44 | $result->exchangeArray($resultArray); | |
45 | } | |
46 | ||
47 | /** | |
48 | * @throws \API_Exception | |
49 | */ | |
50 | protected function validateValues() { | |
51 | if (!empty($this->values['id'])) { | |
52 | throw new \API_Exception('Cannot pass id to Create action. Use Update action instead.'); | |
53 | } | |
54 | parent::validateValues(); | |
55 | } | |
56 | ||
57 | } |