| 1 | <?php |
||
| 19 | abstract class CreateElement extends Action |
||
| 20 | { |
||
| 21 | use SaveElementTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var array |
||
| 25 | */ |
||
| 26 | public $validBodyParams = []; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @inheritdoc |
||
| 30 | */ |
||
| 31 | public $statusCodeSuccess = 201; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @inheritdoc |
||
| 35 | * @return ElementInterface |
||
| 36 | */ |
||
| 37 | abstract protected function newElement(array $config = []): ElementInterface; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @return mixed |
||
| 41 | * @throws \yii\base\Exception |
||
| 42 | * @throws \yii\web\HttpException |
||
| 43 | * @throws \yii\web\UnauthorizedHttpException |
||
| 44 | */ |
||
| 45 | public function run() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Body params that should be set on the record. |
||
| 52 | * |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | protected function validBodyParams(): array |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @param ElementInterface $element |
||
| 62 | * @return bool |
||
| 63 | * @throws \Throwable |
||
| 64 | * @throws \craft\errors\ElementNotFoundException |
||
| 65 | * @throws \yii\base\Exception |
||
| 66 | */ |
||
| 67 | protected function performAction(ElementInterface $element): bool |
||
| 71 | } |
||
| 72 |