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

generateGridViewField() public method

Generates code for Grid View field
public generateGridViewField ( string $attribute, array $fk, yii\db\TableSchema $tableSchema = null ) : string
$attribute string
$fk array
$tableSchema yii\db\TableSchema
return string
    public function generateGridViewField($attribute, $fk, $tableSchema = null)
    {
        if (is_null($tableSchema)) {
            $tableSchema = $this->getTableSchema();
        }
        if (in_array($attribute, $this->hiddenColumns)) {
            return "['attribute' => '{$attribute}', 'visible' => false],\n";
        }
        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);
        $baseClass = StringHelper::basename($this->modelClass);
        if (array_key_exists($attribute, $fk)) {
            $rel = $fk[$attribute];
            if ($rel[self::REL_CLASS] == $baseClass) {
                return "";
            }
            $labelCol = $this->getNameAttributeFK($rel[3]);
            //            $modelRel = $rel[2] ? lcfirst(Inflector::pluralize($rel[1])) : lcfirst($rel[1]);
            $output = "[\r\n                'attribute' => '{$rel['7']}.{$labelCol}',\r\n                'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . "\r\n            ],\n";
            return $output;
        } else {
            return "'{$attribute}" . ($format === 'text' ? "" : ":" . $format) . "',\n";
        }
    }