mootensai\enhancedgii\crud\Generator::generateGridViewFieldIndex PHP Method

generateGridViewFieldIndex() public method

Generates code for Grid View field
public generateGridViewFieldIndex ( string $attribute, array $fk, yii\db\TableSchema $tableSchema = null ) : string
$attribute string
$fk array
$tableSchema yii\db\TableSchema
return string
    public function generateGridViewFieldIndex($attribute, $fk, $tableSchema = null)
    {
        if (is_null($tableSchema)) {
            $tableSchema = $this->getTableSchema();
        }
        if (in_array($attribute, $this->hiddenColumns)) {
            return "['attribute' => '{$attribute}', 'visible' => false],\n";
        }
        //        $humanize = Inflector::humanize($attribute, true);
        if ($tableSchema === false || !isset($tableSchema->columns[$attribute])) {
            if (preg_match('/^(password|pass|passwd|passcode)$/i', $attribute)) {
                return "";
            } else {
                return "'{$attribute}',\n";
            }
        }
        $column = $tableSchema->columns[$attribute];
        $format = $this->generateColumnFormat($column);
        //        if($column->autoIncrement){
        //            return "";
        //        } else
        if (array_key_exists($attribute, $fk) && $attribute) {
            $rel = $fk[$attribute];
            $labelCol = $this->getNameAttributeFK($rel[3]);
            $humanize = Inflector::humanize($rel[3]);
            $id = 'grid-' . Inflector::camel2id(StringHelper::basename($this->searchModelClass)) . '-' . $attribute;
            //            $modelRel = $rel[2] ? lcfirst(Inflector::pluralize($rel[1])) : lcfirst($rel[1]);
            $output = "[\r\n                'attribute' => '{$attribute}',\r\n                'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . ",\r\n                'value' => function(\$model){\r\n                    return \$model->{$rel['7']}->{$labelCol};\r\n                },\r\n                'filterType' => GridView::FILTER_SELECT2,\r\n                'filter' => \\yii\\helpers\\ArrayHelper::map(\\{$this->nsModel}\\{$rel['1']}::find()->asArray()->all(), '{$rel[self::REL_PRIMARY_KEY]}', '{$labelCol}'),\r\n                'filterWidgetOptions' => [\r\n                    'pluginOptions' => ['allowClear' => true],\r\n                ],\r\n                'filterInputOptions' => ['placeholder' => '{$humanize}', 'id' => '{$id}']\r\n            ],\n";
            return $output;
        } else {
            return "'{$attribute}" . ($format === 'text' ? "" : ":" . $format) . "',\n";
        }
    }