Makes data set for export column given attribute data.

@param ModelAttributeData $attribute
@return ModelExportColumnData
349972
protected function makeModelExportColumnDataForAttributeData(ModelAttributeData $attribute)
    {
        return new ModelExportColumnData([
            'hide'     => false,
            'source'   => $attribute->name,
            'strategy' => $this->determineExportColumnStrategyForAttribute($attribute),
        ]);
    }
133424
public function attr($attribute = null)
    {
        if ($this->isNull($attribute)) {
            return $this->attribute;
        }

        return $this->parent->attr($attribute);
    }
1137316
public function resolveModelAttribute($attribute)
    {
        try {
            return $this->formField->resolveModelAttribute($this->model, $attribute);
        }
        catch (Exception $ex) {
            throw new ApplicationException(Lang::get('backend::lang.model.missing_relation', [
                'class' => get_class($this->model),
                'relation' => $attribute
            ]));
        }
    }
454535
protected function checkAttribute($attribute)
    {
        if (!(isset($this->container[$attribute]) || array_key_exists($attribute, $this->container))) {
            throw new ModelException(
                sprintf(
                    "No such attribute '%s'. Available attributes are {%s}",
                    $attribute,
                    join(", ", array_keys($this->fields()))
                )
            );
        }

        return $this;
    }
260422
protected function createAttributeValue(Attribute $attribute, \DOMNode $node, ObjectManager $manager)
    {
        $value = new AttributeValue();
        $value->setAttribute($attribute);

        $manager->persist($value);

        $attribute->addValue($value);

        foreach ($node->childNodes as $childNode) {
            $locale = $childNode->attributes->getNamedItem('locale')->nodeValue;
            $translation = $this->createAttributeValueTranslation(
                $childNode->nodeValue,
                $locale
            );
            $translation->setAttributeValue($value);
            $value->addTranslation($translation);

            $manager->persist($translation);
        }

        return $value;
    }
103478
public function determineValidationRules(ModelAttributeData $attribute, ModelFormFieldData $field)
    {
        $rules = [];

        $required = $field->required();

        switch ($attribute->cast) {

            case AttributeCast::BOOLEAN:
                $required = false;
                break;

            case AttributeCast::INTEGER:
                $rules[] = 'integer';
                break;

            case AttributeCast::FLOAT:
                $rules[] = 'numeric';
                break;

            case AttributeCast::STRING:
                switch ($attribute->type) {

                    case 'enum':
                        $rules[] = 'in:' . implode(',', $attribute->values);
                        break;

                    case 'year':
                        $rules[] = 'digits:4';
                        break;

                    case 'varchar':
                        $rules[] = 'string';
                        if ($attribute->length) {
                            $rules[] = 'max:' . $attribute->length;
                        }
                        break;

                    case 'tinytext':
                        $rules[] = 'string';
                        $rules[] = 'max:255';
                        break;

                    case 'char':
                        $rules[] = 'string';
                        $rules[] = 'max:' . $attribute->length;
                        break;

                    case 'text':
                    case 'mediumtext':
                    case 'longtext':
                    case 'blob';
                    case 'mediumblob';
                    case 'longblob';
                    case 'binary';
                    case 'varbinary';
                        $rules[] = 'string';
                        break;
                }
                break;

            case AttributeCast::DATE:
                switch ($attribute->type) {

                    case 'date':
                    case 'datetime':
                    case 'timestamp':
                        $rules[] = 'date';
                        break;

                    case 'time':
                        $rules[] = 'regex:#^\d{1,2}:\d{1,2}(:\d{1,2})?$#';
                        break;
                }
                break;

            case AttributeCast::JSON:
                $rules[] = 'json';
                break;
        }

        if ($required) {
            // Special case for translated fields: required should be treated as required only if
            // any other translated fields for that locale are entered.
            // This should be handled by the class that requested the attribute validation rules.
            /** @see AbstractFormFieldStoreStrategy */
            $rules[] = 'required';
        } else {
            // Anything that is not required should by default be explicitly nullable
            // since Laravel 5.4.
            $rules[] = 'nullable';
        }

        return $rules;
    }
362347
protected function shouldAttributeBeDisplayedByDefault(ModelAttributeData $attribute, ModelInformationInterface $info)
    {
        if (in_array($attribute->type, [
            'text', 'longtext', 'mediumtext',
            'blob', 'longblob', 'mediumblob',
        ])) {
            return false;
        }

        // Hide active column if the model if activatable
        if ($info->list->activatable && $info->list->active_column == $attribute->name) {
            return false;
        }

        // Hide orderable position column if the model if orderable
        if ($info->list->orderable && $info->list->order_column == $attribute->name) {
            return false;
        }

        // Hide paperclip fields other than the main field
        if (    preg_match('#^(?<field>[^_]+)_(file_name|file_size|content_type|updated_at)$#', $attribute->name, $matches)
            &&  array_has($info->attributes, $matches['field'])
        ) {
            return $info->attributes[ $matches['field'] ]->cast !== AttributeCast::PAPERCLIP_ATTACHMENT;
        }

        // Any attribute that is a foreign key and should be handled with relation-based strategies
        return ! $this->isAttributeForeignKey($attribute->name, $info);
    }
367446
protected function getFilterField(\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute)
    {
        return $this->mappingHelper->getFilterField($attribute);
    }
982479
public function dynamic($model, &$attributes = null)
    {
        // dynamic migration is not allowed when attributes are locked explicitly
        $table_schema = Cache::get($model->getTable());

        if (isset($table_schema['lock_attributes']) && $table_schema['lock_attributes']) {
            return true;
        }

        // Cached attributes
        $cached_attributes = array_map(function($item) { return $item['name']; }, isset($table_schema['attributes']) ? $table_schema['attributes'] : array());

        $config = array(
            'lock_attributes' => false,
            'attributes' => array()
        );

        foreach ($attributes as $field => $value) {
            // extract datatype from field value to migrate
            $datatype = strtolower(gettype($value));

            // ignore 'null' data-types
            if ($datatype == 'null') {
                unset($attributes[$field]);
                continue;
            }

            // Detect large text blocks to declare 'text' datatype.
            if ($datatype == 'string' && strlen($value) > 255) {
                $datatype = 'text';
            }

            if ($datatype !== 'array' && !in_array($field, $cached_attributes)) {
                $config['attributes'][] = array('name' => $field, 'type' => $datatype);
            }
        }

        if (count($config['attributes']) > 0) {
            return $this->migrate($model, $config, true);
        } else {
            return false;
        }
    }
1305918
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 = "[
                'attribute' => '$rel[7].$labelCol',
                'label' => " . $this->generateString(ucwords(Inflector::humanize($rel[5]))) . "
            ],\n";
            return $output;
        } else {
            return "'$attribute" . ($format === 'text' ? "" : ":" . $format) . "',\n";
        }
    }
1099963
public function fill(array $data, $id, $attribute = null)
    {
        $model = $this->find($id, ['*'], $attribute);

        if (empty($model)) {
            throw (new ModelNotFoundException)->setModel($this->model());
        }

        return $model->fill($data);
    }
451906
public function getAttributeAutocompleteField(\Magento\Catalog\Api\Data\ProductAttributeInterface $attribute)
    {
        return $this->attributeHelper->getFilterField($attribute);
    }
16938
protected function enrichColumn($key, ModelExportColumnDataInterface $column, array &$columns)
    {
        // Check if we can enrich, if we must.
        if ( ! isset($this->info->attributes[ $key ])) {

            // if the column data is fully set, no need to enrich
            if ($this->isExportColumnDataComplete($column)) {
                $columns[ $key ] = $column;
                return;
            }

            throw new UnexpectedValueException(
                "Incomplete data for for export column key that does not match known model attribute or relation method. "
                . "Requires at least 'source' value."
            );
        }


        $attributeColumnInfo = $this->makeModelExportColumnDataForAttributeData($this->info->attributes[ $key ]);

        $attributeColumnInfo->merge($column);

        $columns[ $key ] = $attributeColumnInfo;
    }
254490
public function dropDownListRow($model, $attribute, $data = array(), $htmlOptions = array())
	{
		return $this->inputRow(CiiInput::TYPE_DROPDOWN, $model, $attribute, $data, $htmlOptions);
	}
508371
public function setTableAttribute($attribute, $value = null)
    {
        if (is_array($attribute)) {
            return $this->setTableAttributes($attribute);
        }

        $this->tableAttributes[$attribute] = $value;

        return $this;
    }
700110
public function create($attributes = [])
    {
        // Attributes have to be array
        if (!(isset($attributes)) || !is_array($attributes)) {
            throw new \InvalidArgumentException('Undefined attributes', 400);
        }

        // Perform before hook
        $attributes = $this->beforeCreate($attributes);

        // Remove non fillable attributes
        $fields = array_intersect_key($attributes, array_flip($this->fillable));

        // Validate attributes
        $this->setValidationRules();
        $errors = $this->validationErrors($fields);
        if ($errors) {
            throw new Exceptions\ValidationException('Invalid attributes', 400, $errors);
        }

        // Create the model and return its ID
        $result = $this->db()->table($this->table)->insertGetId($fields);

        // Return false if create fails
        if (!$result) {
            throw new \Exception('Could not create the model', 500);
        }

        // Sync many to many relationships
        $this->sync($result, $attributes);

        // Upsert has many relationships
        $this->updateHasMany($result, $attributes);

        // Get the created model
        $model = $this->find($result);

        // Run after hook
        $model = $this->afterCreate($result, $attributes, $model);

        // Return the created model
        return $model;
    }
1067806
protected function makeModelShowFieldDataForAttributeData(ModelAttributeData $attribute, ModelInformationInterface $info)
    {
        $primaryIncrementing = $attribute->name === $this->model->getKeyName() && $info->incrementing;

        return new ModelShowFieldData([
            'source'         => $attribute->name,
            'strategy'       => $this->determineListDisplayStrategyForAttribute($attribute),
            'style'          => $primaryIncrementing ? 'primary-id' : null,
            'label'          => ucfirst(str_replace('_', ' ', snake_case($attribute->name))),
        ]);
    }