relationName = $this->formField->columnName; $this->relationType = $this->model->getRelationType($this->relationName); if (!$this->model->hasRelation($this->relationName)) throw new SystemException(Lang::get('backend::lang.model.missing_relation', ['class'=>get_class($this->controller), 'relation'=>$this->relationName])); } /** * {@inheritDoc} */ public function render() { $this->prepareVars(); return $this->makePartial('relation'); } /** * Prepares the view data */ public function prepareVars() { $this->vars['field'] = $this->makeRenderFormField(); } /** * Makes the form object used for rendering a simple field type */ protected function makeRenderFormField() { $field = clone $this->formField; $relationObj = $this->model->{$this->relationName}(); $relatedObj = $this->model->makeRelation($this->relationName); if ($this->relationType == 'belongsToMany') { $field->type = 'checkboxlist'; $field->value = $relationObj->getRelatedIds(); } else if ($this->relationType == 'belongsTo') { $field->type = 'dropdown'; $foreignKey = $relationObj->getForeignKey(); $field->value = $this->model->$foreignKey; } // @todo Should be configurable $field->options = $relatedObj->all()->lists('name', 'id'); return $this->renderFormField = $field; } }