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

        if (isset($p['relatedObject']) && !$p['relatedObject']->can('update')) {
            throw new HttpException(403, "You do not have access to update '{$p['relatedObject']->descriptor}'");
        }

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

        $p['primaryModel'] = $p['relatedType']->getModel($p['relatedObject']);
        $relations = [];
        $relationSettings = ['template' => 'hierarchy'];
        if (isset($p['relatedObject'])) {
            $fields = $p['primaryModel']->getFields();
            $niceId = $p['relationship']->getNiceId($p['relationshipRole']);
            if (isset($fields[$niceId])) {
                if ($p['relationshipRole'] === 'child') {
                    $relationField = 'parent_object_id';
                } else {
                    $relationField = 'child_object_id';
                }
                if (isset($p['relation'])) {
                    $tabularId = $fields[$niceId]->model->tabularId;
                    $handler = $fields[$niceId]->model->_moduleHandler;
                    $fields[$niceId]->model = $p['relation'];
                    $relationSettings['lockFields'] = ['object_id'];
                    $fields[$niceId]->model->tabularId = $handler;
                    $fields[$niceId]->model->_moduleHandler = $handler;
                } else {
                    $fields[$niceId]->resetModel();
                    $fields[$niceId]->model->{$relationField} = $p['relatedObject']->primaryKey;
                }
                $relations[$fields[$niceId]->model->tabularId] = $fields[$niceId]->model;
            } else {
                throw new HttpException(403, "Invalid relationship!");
            }
        }

        $p['primaryModel']->setRelationModels($relations);
        if (!empty($_POST)) {
            $p['primaryModel']->load($_POST);
            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 = $p['type']->primaryModel;
                    Yii::$app->response->trigger = [
                        ['refresh', '.model-' . $primaryModelClass::baseClassName()],
                    ];
                } else {
                    Yii::$app->response->redirect = $p['primaryModel']->getUrl('view');
                }
            }
        }
        if (!($p['form'] = $p['relatedType']->getForm($p['primaryModel'], ['relationSettings' => $relationSettings, 'subform' => $p['objectRelationName']]))) {
            throw new HttpException(403, "There is nothing to create for {$p['type']->title->getPlural(true)}");
        }
        $p['form']->ajax = true;
    }
public function actionLink()
    {
        $p = $this->_parseParams();
        $this->_checkParams($p, ['type', 'relatedObject', 'relatedType']);
        $this->params = &$p;

        if (isset($p['relatedObject']) && !$p['relatedObject']->can('update')) {
            throw new HttpException(403, "You do not have access to update '{$p['relatedObject']->descriptor}'");
        }

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

        $p['primaryModel'] = $p['relatedType']->getModel($p['relatedObject']);
        $relations = [];
        $relationSettings = ['template' => 'hierarchy'];
        if (isset($p['relatedObject'])) {
            $fields = $p['primaryModel']->getFields();
            $niceId = $p['relationship']->getNiceId($p['relationshipRole']);
            if (isset($fields[$niceId])) {
                if ($p['relationshipRole'] === 'child') {
                    $relationField = 'parent_object_id';
                } else {
                    $relationField = 'child_object_id';
                }
                if (isset($p['relation'])) {
                    $tabularId = $fields[$niceId]->model->tabularId;
                    $handler = $fields[$niceId]->model->_moduleHandler;
                    $fields[$niceId]->model = $p['relation'];
                    $relationSettings['lockFields'] = ['object_id'];
                    $fields[$niceId]->model->tabularId = $handler;
                    $fields[$niceId]->model->_moduleHandler = $handler;
                } else {
                    $fields[$niceId]->resetModel();
                    $fields[$niceId]->model->{$relationField} = $p['relatedObject']->primaryKey;
                }
                $relations[$fields[$niceId]->model->tabularId] = $fields[$niceId]->model;
            } else {
                throw new HttpException(403, "Invalid relationship!");
            }
        }

        $p['primaryModel']->setRelationModels($relations);
        if (!empty($_POST)) {
            $p['primaryModel']->load($_POST);
            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 = $p['type']->primaryModel;
                    Yii::$app->response->trigger = [
                        ['refresh', '.model-' . $primaryModelClass::baseClassName()],
                    ];
                } else {
                    Yii::$app->response->redirect = $p['primaryModel']->getUrl('view');
                }
            }
        }
        if (!($p['form'] = $p['relatedType']->getForm($p['primaryModel'], ['relationSettings' => $relationSettings, 'subform' => $p['objectRelationName']]))) {
            throw new HttpException(403, "There is nothing to create for {$p['type']->title->getPlural(true)}");
        }
        $p['form']->ajax = true;
    }
[[@doctodo method_description:actionLink]].

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