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 * Base class for all "Create" api actions.
27 * @method $this setValues(array $values) Set all field values from an array of key => value pairs.
28 * @method $this addValue($field, $value) Set field value.
29 * @method array getValues() Get field values.
31 * @package Civi\Api4\Generic
33 abstract class AbstractCreateAction
extends AbstractAction
{
40 protected $values = [];
47 public function getValue($key) {
48 return isset($this->values
[$key]) ?
$this->values
[$key] : NULL;
52 * @throws \API_Exception
54 protected function validateValues() {
55 $unmatched = $this->checkRequiredFields($this->getValues());
57 throw new \
API_Exception("Mandatory values missing from Api4 {$this->getEntityName()}::{$this->getActionName()}: " . implode(", ", $unmatched), "mandatory_missing", ["fields" => $unmatched]);