for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Copyright (c) Flipbox Digital Limited
* @license https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
* @link https://github.com/flipboxfactory/craft-ember/
*/
namespace flipbox\craft\ember\actions\elements;
use Craft;
use craft\base\ElementInterface;
use yii\base\Action;
* @author Flipbox Factory <[email protected]>
* @since 2.0.0
abstract class CreateElement extends Action
{
use SaveElementTrait;
* @var array
public $validBodyParams = [];
* @inheritdoc
public $statusCodeSuccess = 201;
* @return ElementInterface
abstract protected function newElement(array $config = []): ElementInterface;
* @return mixed
* @throws \yii\base\Exception
* @throws \yii\web\HttpException
* @throws \yii\web\UnauthorizedHttpException
public function run()
return $this->runInternal($this->newElement());
}
* Body params that should be set on the record.
*
* @return array
protected function validBodyParams(): array
return $this->validBodyParams;
* @param ElementInterface $element
* @return bool
* @throws \Throwable
* @throws \craft\errors\ElementNotFoundException
protected function performAction(ElementInterface $element): bool
return Craft::$app->getElements()->saveElement($element);