An Array of Fields to Exclude on Clone.

When cloning a Model ceratin data might need to be skipped
either because it is irrelevant (such as datestamps) or
because it is primary or unique data in the database.

@return array
432308
public function excludeOnClone()
    {
        return [
            $this->model->getKeyName(),
            $this->model->getCreatedAtColumn(),
            $this->model->getUpdatedAtColumn(),
        ];
    }
1255469
public function toArray()
    {
        $object = [];

        if (static::$type) {
            $object['type'] = static::$type;
        }

        $attributes = array_merge(
            static::getTypeAttributes(),
            static::$commonAttributes
        );

        foreach ($attributes as $attribute) {
            $value = $this->{$attribute};

            if ($value !== null) {
                $toCopy = $value;

                //Clone object to prevent original object to be changed
                if (is_object($value)) {
                    $toCopy = clone $value;
                }

                $object[$attribute] = $toCopy;
            }

            if (static::$type == 'object' && $attribute == 'properties') {
                foreach ($object[$attribute] as $key => $property) {
                    if ($property instanceof BaseValidator) {
                        $object[$attribute]->{$key} = $property->toArray();
                    }
                }
                //fix type to array
                $object[$attribute] = (array)$object[$attribute];
            } elseif (in_array($attribute, ['allOf', 'anyOf', 'oneOf'])) {
                if (isset($object[$attribute]) && $object[$attribute] !== null) {
                    foreach ($object[$attribute] as $key => $property) {
                        if ($property instanceof BaseValidator) {
                            $object[$attribute][$key] = $property->toArray();
                        }
                    }
                }
            } elseif (in_array($attribute, ['items', 'not'])) {
                if (isset($object[$attribute])
                    && $object[$attribute]
                    && $object[$attribute] instanceof BaseValidator
                ) {
                    $object[$attribute] = $object[$attribute]->toArray();
                }
            }
        }

        return $object;
    }
314067
public function generateFormFields() : array {
		$result = [
			'success' => false,
			'error' => [],
			'data' => []
		];
		// details
		$details = [];
		if (!empty($this->collection['details'])) {
			$this->disassembleCollectionObject($this->collection['details'], $details);
		}
		// step 1: fields
		foreach ($this->fields as $k => $v) {
			if (!$this->skipExportField($k, $v)) continue;
			// if we have detail
			if (!empty($details[$k])) {
				$result['data'][$k . '[' . $v['options']['multiple_column'] . ']'] = [
					'name' => $v['options']['label_name'],
					'type' => $this->determineFieldType($v['options']['multiple_column'], $v)
				];
				continue;
			}
			// regular field
			$result['data'][$k] = [
				'name' => $v['options']['label_name'],
				'type' => $this->determineFieldType($k, $v)
			];
		}
		// step 2: detail fields
		foreach ($this->detail_fields as $k => $v) {
			foreach ($v['elements'] as $k2 => $v2) {
				if (!$this->skipExportField($k2, $v2)) continue;
				$result['data'][$k . '[' . $k2 . ']'] = [
					'name' => (isset($details[$k]['name']) ? ($details[$k]['name'] . ' - ') : '') . $v2['options']['label_name'],
					'type' => $this->determineFieldType($k2, $v2)
				];
			}
		}
		$result['success'] = true;
		return $result;
	}
634521
protected function getCopyDestinations()
    {
        $copyFields = $this->config()->copy_fields;
        if ($copyFields) {
            return $copyFields;
        }
        // Fallback to default field
        $df = $this->getDefaultField();
        return array($df);
    }
766609
protected function getRelationFields() {
        $fields = [];
        foreach ($this->relations as $relation) {
            $fields = array_merge($fields, $relation->getLinkKeys());
        }
        return array_unique($fields);
    }
118006
public function getPrimaryKeys(): array
    {
        $primaryColumns = [];
        foreach ($this->getColumns() as $column) {
            if ($column->getAbstractType() == 'primary' || $column->getAbstractType() == 'bigPrimary') {
                if (!in_array($column->getName(), $this->primaryKeys)) {
                    //Only columns not listed as primary keys already
                    $primaryColumns[] = $column->getName();
                }
            }
        }

        return array_unique(array_merge($this->primaryKeys, $primaryColumns));
    }
532107
final public function sanitizedAttributes () : array
	{
        $dbObject 			= Database::getInstance();
		$cleanAttributes 	= [];
		foreach ($this->attributes() as $key => $value):
			if (isset($value))
				$cleanAttributes[$key] = $dbObject->escapeValue($value);
		endforeach;
		return $cleanAttributes;
	}
634727
public function HiddenFields()
    {
        $hiddenFields = new FieldList();
        $dataFields = $this->dataFields();

        if ($dataFields) {
            foreach ($dataFields as $field) {
                if ($field instanceof HiddenField) {
                    $hiddenFields->push($field);
                }
            }
        }

        return $hiddenFields;
    }
954237
public function toObjectArray() : array
    {
        if ($this->isEmpty()) {
            return [];
        }

        $skeleton = $this->_model;

        return array_map(function ($entry) use ($skeleton) {
            return Model::cloneResult($skeleton, $entry);
        }, $this->toArray());
    }
1224239
public function getDuplicates()
    {
        $result = [];
        foreach ($this->data as $key => $data) {
            $result[$key] = array_filter($data, function ($v /*, $k*/) {
                return $v > 1;
            }, ARRAY_FILTER_USE_BOTH);

        }
        return $result;
    }
833811
public function changedFieldNames()
    {
        $diffed = clone $this->fromRecord;
        $fields = array_keys($diffed->toMap());

        $changedFields = [];

        foreach ($fields as $field) {
            if (in_array($field, $this->ignoredFields)) {
                continue;
            }
            if ($this->fromRecord->$field != $this->toRecord->$field) {
                $changedFields[] = $field;
            }
        }

        return $changedFields;
    }
1108140
public function performReadonlyTransformation()
    {
        $clone = clone $this;
        
        foreach ($clone->fields as $dim => $field) {
            $clone->fields[$dim] = $field->performReadonlyTransformation();
        }
        
        $clone->setReadonly(true);
        
        return $clone;
    }
592981
public function getFieldsValidDataAttributes()
    {
        $result = [];
        $formConfiguration = $this->getFormObject()->getConfiguration();
        $formResult = $this->getFormObject()->getFormResult();

        foreach ($formConfiguration->getFields() as $field) {
            $fieldName = $field->getName();

            if (false === $formResult->fieldIsDeactivated($field)
                && false === $formResult->forProperty($fieldName)->hasErrors()
            ) {
                $result[self::getFieldDataValidKey($fieldName)] = '1';
            }
        }

        return $result;
    }
726836
protected function getUnselectedFields() {
    $profile_fields = $this->fieldStorage->loadByProperties(['entity_type' => 'profile', 'bundle' => 'profile']);
    $settings = $this->configFactory->get('social_profile_fields.settings');
    $empty = [];

    /** @var \Drupal\field\Entity\FieldConfig $value */
    foreach ($profile_fields as $key => $value) {
      $sval = $settings->get(str_replace('.', '_', $key));

      if (isset($sval) && $sval == FALSE) {
        $empty[] = $value->getName();
      }
    }
    return $empty;
  }
371889
protected function getClassNameRemappingFields()
    {
        $dataClasses = ClassInfo::getValidSubClasses(DataObject::class);
        $schema = DataObject::getSchema();
        $remapping = [];

        foreach ($dataClasses as $className) {
            $fieldSpecs = $schema->fieldSpecs($className);
            foreach ($fieldSpecs as $fieldName => $fieldSpec) {
                if (Injector::inst()->create($fieldSpec, 'Dummy') instanceof DBClassName) {
                    $remapping[$className][] = $fieldName;
                }
            }
        }

        return $remapping;
    }
1251885
public function getUniqueFieldNames()
    {
        $results = [ $this->getPrimaryFieldName() ];
        if (!isset($this->data['fields']) || empty($this->data['fields'])) {
            return $results;
        }

        $table = $this->data['name'];
        foreach ($this->data['fields'] as $field) {
            $name = $table . '_' . $field['name'];

            if ($field['field']['type'] === 'uuid') {
                $results[] = $name;
                continue;
            }

            if (!isset($field['validation'])) {
                continue;
            }

            foreach ($field['validation'] as $validation) {
                if ($validation['method'] === 'unique') {
                    $results[] = $name;
                }
            }
        }

        return $results;
    }
225002
public function getDerivedFields()
    {
        if ($this->derivedFields === null) {
            $this->derivedFields = array();

            foreach ($this->getFieldsIterator() as $name => $field) {
                if (count($field['lookup_chain']) < 2) {
                    continue;
                }

                $key = sha1($field['base'] . serialize($field['lookup_chain']));
                $fieldname = "{$field['class']}:{$field['field']}";

                if (isset($this->derivedFields[$key])) {
                    $this->derivedFields[$key]['fields'][$fieldname] = $fieldname;
                    SearchIntrospection::add_unique_by_ancestor($this->derivedFields['classes'], $field['class']);
                } else {
                    $chain = array_reverse($field['lookup_chain']);
                    array_shift($chain);

                    $this->derivedFields[$key] = array(
                        'base' => $field['base'],
                        'fields' => array($fieldname => $fieldname),
                        'classes' => array($field['class']),
                        'chain' => $chain
                    );
                }
            }
        }

        return $this->derivedFields;
    }