public function activeField($attribute)
{
$column = $this->generator->getColumnByAttribute($attribute);
if (!$column) {
return;
}
$relation = $this->generator->getRelationByColumn($this->generator->modelClass, $column);
if ($relation) {
switch (true) {
case !$relation->multiple:
$pk = key($relation->link);
$name = $this->generator->getModelNameAttribute($relation->modelClass);
$method = __METHOD__;
switch ($this->inputWidget) {
case 'select2':
$code = <<<EOS
// generated by {$method}
\$form->field(\$model, '{$column->name}')->widget(\\kartik\\select2\\Select2::classname(), [
'name' => 'class_name',
'model' => \$model,
'attribute' => '{$column->name}',
'data' => \\yii\\helpers\\ArrayHelper::map({$relation->modelClass}::find()->all(), '{$pk}', '{$name}'),
'options' => [
'placeholder' => {$this->generator->generateString('Type to autocomplete')},
'multiple' => false,
'disabled' => (isset(\$relAttributes) && isset(\$relAttributes['{$column->name}'])),
]
]);
EOS;
break;
default:
$code = <<<EOS
// generated by {$method}
\$form->field(\$model, '{$column->name}')->dropDownList(
\\yii\\helpers\\ArrayHelper::map({$relation->modelClass}::find()->all(), '{$pk}', '{$name}'),
[
'prompt' => {$this->generator->generateString('Select')},
'disabled' => (isset(\$relAttributes) && isset(\$relAttributes['{$column->name}'])),
]
);
EOS;
break;
}
return $code;
default:
return;
}
}
}