lib/controllers/ObjectController.php
public function actionCreate()
    {
        $p = $this->_parseParams();
        $this->_checkParams($p, ['type']);
        $this->params = &$p;

        if (!Yii::$app->gk->canGeneral('create', $p['type']->primaryModel)) {
            throw new HttpException(403, "You do not have access to create {$p['type']->title->getPlural(true)}");
        }

        Yii::$app->response->view = 'create';
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->taskOptions = ['title' => 'Create ' . $p['type']->title->getSingular(true) , 'width' => '800px'];

        $p['primaryModel'] = $p['type']->getModel();
        $relations = [];
        if (isset($p['relatedObject'])) {
            $fields = $p['primaryModel']->getFields();
            $companionNiceId = $p['relationship']->getCompanionNiceId($p['relationshipRole']);
            if (isset($fields[$companionNiceId])) {
                if ($p['relationshipRole'] === 'child') {
                    $relationField = 'parent_object_id';
                } else {
                    $relationField = 'child_object_id';
                }
                $p['primaryModel']->setIndirectObject($p['relatedObject']);
                $fields[$companionNiceId]->model->{$relationField} = $p['relatedObject']->primaryKey;
                $relations[$fields[$companionNiceId]->model->tabularId] = $fields[$companionNiceId]->model;
            } else {
                // \d(array_keys($fields));
                // \d($p['objectRelationName']);
                throw new HttpException(403, "Invalid relationship!");
            }
        }

        $p['primaryModel']->setRelationModels($relations);
        if (!empty($_POST)) {
            $p['primaryModel']->load($_POST);
            if ($p['primaryModel']->getBehavior('Storage') !== null) {
                $p['primaryModel']->loadPostFile();
            }
            if (!$p['primaryModel']->save()) {
                Yii::$app->response->error = 'Unable to create object!';
            } else {
                Yii::$app->response->task = 'status';
                Yii::$app->response->success = '<em>' . $p['primaryModel']->descriptor . '</em> was created successfully.';
                if (isset($p['relatedType'])) {
                    $primaryModelClass = get_class($p['primaryModel']);
                    Yii::$app->response->trigger = [
                        ['refresh', '.model-' . $primaryModelClass::baseClassName()],
                    ];
                } else {
                    Yii::$app->response->redirect = $p['primaryModel']->getUrl('view');
                }
            }
        }

        if (!($p['form'] = $p['type']->getForm($p['primaryModel'], ['relationSettings' => false]))) {
            throw new HttpException(403, "There is nothing to create for {$p['type']->title->getPlural(true)}");
        }
        $p['form']->ajax = true;
    }
public function actionCreate()
    {
        $p = $this->_parseParams();
        $this->_checkParams($p, ['type']);
        $this->params = &$p;

        if (!Yii::$app->gk->canGeneral('create', $p['type']->primaryModel)) {
            throw new HttpException(403, "You do not have access to create {$p['type']->title->getPlural(true)}");
        }

        Yii::$app->response->view = 'create';
        Yii::$app->response->task = 'dialog';
        Yii::$app->response->taskOptions = ['title' => 'Create ' . $p['type']->title->getSingular(true) , 'width' => '800px'];

        $p['primaryModel'] = $p['type']->getModel();
        $relations = [];
        if (isset($p['relatedObject'])) {
            $fields = $p['primaryModel']->getFields();
            $companionNiceId = $p['relationship']->getCompanionNiceId($p['relationshipRole']);
            if (isset($fields[$companionNiceId])) {
                if ($p['relationshipRole'] === 'child') {
                    $relationField = 'parent_object_id';
                } else {
                    $relationField = 'child_object_id';
                }
                $p['primaryModel']->setIndirectObject($p['relatedObject']);
                $fields[$companionNiceId]->model->{$relationField} = $p['relatedObject']->primaryKey;
                $relations[$fields[$companionNiceId]->model->tabularId] = $fields[$companionNiceId]->model;
            } else {
                // \d(array_keys($fields));
                // \d($p['objectRelationName']);
                throw new HttpException(403, "Invalid relationship!");
            }
        }

        $p['primaryModel']->setRelationModels($relations);
        if (!empty($_POST)) {
            $p['primaryModel']->load($_POST);
            if ($p['primaryModel']->getBehavior('Storage') !== null) {
                $p['primaryModel']->loadPostFile();
            }
            if (!$p['primaryModel']->save()) {
                Yii::$app->response->error = 'Unable to create object!';
            } else {
                Yii::$app->response->task = 'status';
                Yii::$app->response->success = '<em>' . $p['primaryModel']->descriptor . '</em> was created successfully.';
                if (isset($p['relatedType'])) {
                    $primaryModelClass = get_class($p['primaryModel']);
                    Yii::$app->response->trigger = [
                        ['refresh', '.model-' . $primaryModelClass::baseClassName()],
                    ];
                } else {
                    Yii::$app->response->redirect = $p['primaryModel']->getUrl('view');
                }
            }
        }

        if (!($p['form'] = $p['type']->getForm($p['primaryModel'], ['relationSettings' => false]))) {
            throw new HttpException(403, "There is nothing to create for {$p['type']->title->getPlural(true)}");
        }
        $p['form']->ajax = true;
    }
[[@doctodo method_description:actionCreate]].

@throws HttpException [[@doctodo exception_description:HttpException]]