Returns fields to be displayed on scaffolded template

@param array $associations Associations list.
@return array
762950
protected function _scaffoldFields(array $associations = [])
    {
        $action = $this->_action();
        $scaffoldFields = (array)$action->getConfig('scaffold.fields');
        if (!empty($scaffoldFields)) {
            $scaffoldFields = Hash::normalize($scaffoldFields);
        }

        if (empty($scaffoldFields) || $action->getConfig('scaffold.autoFields')) {
            $cols = $this->_table()->getSchema()->columns();
            $cols = Hash::normalize($cols);

            $scope = $action->getConfig('scope');
            if ($scope === 'entity' && !empty($associations['manyToMany'])) {
                foreach ($associations['manyToMany'] as $alias => $options) {
                    $cols[sprintf('%s._ids', $options['entities'])] = [
                        'multiple' => true
                    ];
                }
            }

            $scaffoldFields = array_merge($cols, $scaffoldFields);
        }

        // Check for blacklisted fields
        $blacklist = $action->getConfig('scaffold.fields_blacklist');
        if (!empty($blacklist)) {
            $scaffoldFields = array_diff_key($scaffoldFields, array_combine($blacklist, $blacklist));
        }

        // Make sure all array values are an array
        foreach ($scaffoldFields as $field => $options) {
            if (!is_array($options)) {
                $scaffoldFields[$field] = (array)$options;
            }

            $scaffoldFields[$field] += ['formatter' => null];
        }

        $fieldSettings = $action->getConfig('scaffold.field_settings');
        if (empty($fieldSettings)) {
            $fieldSettings = [];
        }
        $fieldSettings = array_intersect_key($fieldSettings, $scaffoldFields);
        $scaffoldFields = Hash::merge($scaffoldFields, $fieldSettings);

        return $scaffoldFields;
    }
650856
public function models($action = null)
    {
        $settings = $this->relatedModels(null, $action);

        if ($settings === true) {
            return $this->getAssociatedByType(['oneToOne', 'manyToMany', 'manyToOne']);
        }

        if (empty($settings)) {
            return [];
        }

        if (is_string($settings)) {
            $settings = [$settings];
        }

        return $this->getAssociatedByName($settings);
    }
11721
public function getFields()
    {
        $fields = [];
        foreach ($this->fieldsets as $fieldset) {
            $fields = array_merge($fields, $fieldset->getAllFields());
        }
        return $fields;
    }
121401
public function getCMSFields()
    {
        $fields = $this->scaffoldFormFields(
            array(
                // Don't allow has_many/many_many relationship editing before the record is first saved
                'includeRelations' => ($this->ID > 0),
                'tabbed' => true,
                'ajaxSafe' => true
            )
        );
        $fields->removeByName('HasMain');
        $fields->addFieldsToTab(
            'Root.Main',
            array(
                TextField::create(
                    'Title',
                    _t('PlaceablePageType.TITLE', 'Title')
                )->setMaxLength(17),
                TextField::create(
                    'Description',
                    _t('PlaceablePageType.DESCRIPTION', 'Description')
                ),
                UploadField::create(
                    'Icon',
                    _t('PlaceablePageType.ICON', 'Icon')
                )
            )
        );

        $fields->addFieldToTab(
            'Root.Pages',
            GridField::create(
                'Pages',
                _t('PlaceablePageType.PAGES', 'Pages'),
                $this->Pages()
            )
        );

        $fields->addFieldToTab(
            'Root.Regions',
            GridField::create(
                'Regions',
                _t('PlaceablePageType.SECTIONS', 'Regions'),
                $this->Regions(),
                GridFieldConfig_MultiClass::create(
                    $this->Regions(),
                    singleton('RegionObject_Preset')->SubClassNames
                )
            )
        );
        return $fields;
    }
895460
def associations
      @associations ||= [].tap do |fields|
        @model.reflect_on_all_associations.each do |association|
          fields << resolve(association.macro, association.name)
        end
      end
    end
870765
public function getCMSFields()
    {
        $fields = $this->scaffoldFormFields(
            array(
                // Don't allow has_many/many_many relationship editing before the record is first saved
                'includeRelations' => ($this->ID > 0),
                'tabbed' => true,
                'ajaxSafe' => true
            )
        );
        $fields->removeByName('PresetID');
        $fields->addFieldToTab(
            'Root.Main',
            ReadonlyField::create(
                'PresetName',
                _t('PlaceableObject.PRESET', 'Preset')
            )->setValue($this->Preset()->Title)
        );
        $this->extend('updateCMSFields', $fields);
        return $fields;
    }
1113752
protected function getHeaders(): array
    {
        $displayColumns = $this->getDisplayColumns();

        if (empty($displayColumns)) {
            return [];
        }

        $table = TableRegistry::get($this->search->get('model'));

        $associationLabels = Utility::instance()->getAssociationLabels($table);
        $searchableFields = Utility::instance()->getSearchableFields($table, $this->user);

        $result = [];
        foreach ($displayColumns as $column) {
            $label = $column;
            if (array_key_exists($label, $searchableFields)) {
                $label = $searchableFields[$label]['label'];
            }

            list($fieldModel, ) = pluginSplit($column);
            if (array_key_exists($fieldModel, $associationLabels)) {
                $label .= ' (' . $associationLabels[$fieldModel] . ')';
            }

            $result[] = $label;
        }

        return $result;
    }
852679
protected function getFieldsFromModels($models)
    {
        if (!$models->first()) {
            // No models, we can't add any columns.
            return [];
        }

        $model = $models->first();

        // These are the Laravel basic timestamp fields which we don't want to display, by default
        $timestamp_fields = ['created_at', 'updated_at', 'deleted_at'];
        // Grab the basic fields from the first model
        $fields = array_keys($model->toArray());
        // Remove the timestamp fields
        $fields = array_diff($fields, $timestamp_fields);
        if ($model->isSortable) {
            // Add the fields from the model's sortable array
            $fields = array_unique(array_merge($fields, $model->getSortable()));
        }

        return $fields;
    }
218216
public function getCachedField(): array
    {
        if (empty($this->cached) || !is_array($this->cached)) {
            $this->cached = [];
        }

        return $this->cached;
    }
830546
public function fields(array $fields = null)
    {
        if ($fields === null) {
            return $this->container;
        }

        $output = [];

        foreach ($fields as $name) {
            if (isset($this->container[$name]) || array_key_exists($name, $this->container)) {
                $output[$name] = $this->container[$name];
            } else {
                throw new \InvalidArgumentException(
                    sprintf(
                        "No such field '%s'. Existing fields are {%s}",
                        $name,
                        join(', ', array_keys($this->container))
                    )
                );
            }
        }

        return $output;
    }
1060283
public function getIndexHeaderCells(array $fields = null)
    {
        $stub = $this->getStubContent('index.header.cell.blade', $this->template);
        $fields = $this->getFieldsToDisplay($fields);
        $rows = '';

        foreach ($fields as $field) {
            if ($field->isOnIndexView) {
                $row = $stub;
                $this->replaceFieldTitle($row, $this->getTitle($field->getLabel(), true))
                    ->replaceCommonTemplates($row, $field);
                $rows .= $row . PHP_EOL;
            }
        }

        return $rows;
    }
399972
public static function getRealRelationFields(string $module) : array
    {
        $relation = [];

        $table = TableRegistry::getTableLocator()->get($module);
        foreach ($table->associations() as $association) {
            $relation[] = $association->getName();
        }

        return $relation;
    }
705194
public function scaffoldMappableFields($includerelations = true)
    {
        $map = $this->getMappableFieldsForClass($this->objectClass);
        //set up 'dot notation' (Relation.Field) style mappings
        if ($includerelations) {
            if ($has_ones = singleton($this->objectClass)->hasOne()) {
                foreach ($has_ones as $relationship => $type) {
                    $fields = $this->getMappableFieldsForClass($type);
                    foreach ($fields as $field => $title) {
                        $map[$relationship.".".$field] =
                            $this->formatMappingFieldLabel($relationship, $title);
                    }
                }
            }
        }

        return $map;
    }
510051
protected function _associations(array $whitelist = [])
    {
        $table = $this->_table();

        $associationConfiguration = [];

        $associations = $table->associations();

        $keys = $associations->keys();
        if (!empty($whitelist)) {
            $keys = array_intersect($keys, array_map('strtolower', $whitelist));
        }
        foreach ($keys as $associationName) {
            $association = $associations->get($associationName);
            $type = $association->type();

            if (!isset($associationConfiguration[$type])) {
                $associationConfiguration[$type] = [];
            }

            $assocKey = $association->getName();
            $associationConfiguration[$type][$assocKey]['model'] = $assocKey;
            $associationConfiguration[$type][$assocKey]['type'] = $type;
            $associationConfiguration[$type][$assocKey]['primaryKey'] = $association->getTarget()->getPrimaryKey();
            $associationConfiguration[$type][$assocKey]['displayField'] = $association->getTarget()->getDisplayField();
            $associationConfiguration[$type][$assocKey]['foreignKey'] = $association->getForeignKey();
            $associationConfiguration[$type][$assocKey]['propertyName'] = $association->getProperty();
            $associationConfiguration[$type][$assocKey]['plugin'] = pluginSplit($association->getClassName())[0];
            $associationConfiguration[$type][$assocKey]['controller'] = $assocKey;
            $associationConfiguration[$type][$assocKey]['entity'] = Inflector::singularize(Inflector::underscore($assocKey));
            $associationConfiguration[$type][$assocKey]['entities'] = Inflector::underscore($assocKey);

            $associationConfiguration[$type][$assocKey] = array_merge($associationConfiguration[$type][$assocKey], $this->_action()->getConfig('association.' . $assocKey) ?: []);
        }

        return $associationConfiguration;
    }
770969
private function otherFields(array $fields): array
    {
        $unused = array_diff(self::OTHER_ADVANCED_FIELDS, array_keys($fields));

        $other_fileds = [];

        foreach ($unused as $tag) {
            $other_fileds[$tag] = GedcomTag::getLabel($tag);
        }

        return $other_fileds;
    }
642646
protected function formatRelationMappings($mappings, $associationMappings)
    {
        $types = $this->getTypes();

        foreach ($associationMappings as $fieldName => $relation) {
            if ($relation['type'] !== ClassMetadataInfo::ONE_TO_MANY) {
                $mappings[sprintf('%s_%s', $fieldName, 'id')] = $types['string'];
            }
        }

        return $mappings;
    }
1371320
public function mapFormFields($fields)
    {
        $_fields = [];

        foreach ($fields as $key => $options) {
            $_options = $this->config('formFieldOptions');

            if (is_array($options)) {
                $_fields[$key] = array_merge($_options, $options);
            } else {
                $_fields[$options] = $_options;
            }
        }

        return $_fields;
    }