/*
A simple field same-value checker.

@param array $data
@return array
@see {@link AWRequiredFields}
186379
public function extendedRequiredFieldsNotSame($data = null)
    {
        $check = array('ActionID','NextActionID');
        foreach ($check as $fieldName) {
            if (!isset($data[$fieldName])) {
                return self::$extendedMethodReturn;
            }
        }
        // Have we found some identical values?
        if ($data[$check[0]] == $data[$check[1]]) {
            // Used to display to the user, so the first of the array is fine
            self::$extendedMethodReturn['fieldName'] = $check[0];
            self::$extendedMethodReturn['fieldValid'] = false;
            self::$extendedMethodReturn['fieldMsg'] = _t(
                'WorkflowTransition.TRANSITIONLOOP',
                'A transition cannot lead back to its parent action.'
            );
        }
        return self::$extendedMethodReturn;
    }
308720
public function validate(array $data)
    {
        $errors = [];

        if (empty($data['name'])) {
            $errors[] = ['path' => '/name', 'message' => 'name can not be empty.'];
        }

        if (empty($data['type'])) {
            $errors[] = ['path' => '/type', 'message' => 'type can not be empty.'];
        }

        if (empty($data['scheduledDate'])) {
            $errors[] = ['path' => '/scheduledDate', 'message' => 'scheduledDate can not be empty.'];
        }

        return $errors;
    }
660059
public function secureFields(array $data)
    {
        $data = $this->_normalizeData($data);

        $fields = [];
        foreach ($this->_selects as $select) {
            if ($data[$select] === false || $data[$select] === null) {
                continue;
            }

            $fields[] = $data['name'] . '[' . $select . ']';
        }

        return $fields;
    }
294290
private function _postfields($data)
    {
        if (is_array($data)) {
            if ($this->is_array_multidim($data)) {
                $data = $this->http_build_multi_query($data);
            } else {
                // Fix "Notice: Array to string conversion" when $value in
                // curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array
                // that contains an empty array.
                foreach ($data as $key => $value) {
                    if (is_array($value) && empty($value)) {
                        $data[$key] = '';
                    }
                }
            }
        }

        return $data;
    }
942427
protected static function validateCriteria(array $data, array $fields): array
    {
        foreach (array_keys($data) as $key) {
            if (in_array($key, $fields)) {
                continue;
            }
            unset($data[$key]);
        }

        return $data;
    }
1179166
public function checkMandatoryColumns(array $data)
    {
        $diff = array_diff($this->mandatoryColumns, array_keys($data));

        if (\count($diff) > 0) {
            throw new \UnexpectedValueException(
                Translator::getInstance()->trans(
                    'The following columns are missing: %columns',
                    [
                        '%columns' => implode(', ', $diff)
                    ]
                )
            );
        }
    }
1036926
public static function arrayColumns(array $data)
    {
        // Count the amount of values from the source input
        $count = count($data);

        if ($count === 0) {
            return false;
        }

        if ($count === 1) {
            return array_keys($data[0]);
        }

        if (isset($data[0])) {
            return array_keys($data[0]);
        } else {
            return false;
        }
    }
1234460
public static function key(array $data) {
		$data += [
			'fields' => [],
			'locked' => [],
			'excluded' => []
		];
		return static::_compile(
			array_keys(Set::flatten($data['fields'])),
			$data['locked'],
			array_keys($data['excluded'])
		);
	}
34846
public function fill($data)
    {
        // Field value is already setted.
//        if (!is_null($this->value)) {
//            return;
//        }

        if (is_array($this->column)) {
            foreach ($this->column as $key => $column) {
                $this->value[$key] = array_get($data, $column);
            }

            return;
        }

        $this->value = array_get($data, $this->column);
    }
463283
public function applyOrderAndAliases(array $data)
    {
        if ($this->orderAndAliases === null) {
            return $data;
        }

        $processedData = [];

        foreach ($this->orderAndAliases as $key => $value) {
            if (\is_integer($key)) {
                $fieldName = $value;
                $fieldAlias = $value;
            } else {
                $fieldName = $key;
                $fieldAlias = $value;
            }

            $processedData[$fieldAlias] = null;
            if (array_key_exists($fieldName, $data)) {
                $processedData[$fieldAlias] = $data[$fieldName];
            }
        }

        return $processedData;
    }
535432
protected static function applyDefaultValues(array $data): array
    {
        foreach ($data as $tableName => $sections) {
            if (empty($GLOBALS['TCA'][$tableName]['columns'])) {
                continue;
            }

            $fields = $sections['fields'];

            foreach ($GLOBALS['TCA'][$tableName]['columns'] as $tcaFieldName => $tcaFieldConfiguration) {
                // Skip if field was already imported
                if (in_array($tcaFieldName, $fields)) {
                    continue;
                }
                // Skip if field is an enable-column (it's expected that those fields have proper DBMS defaults)
                if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']) && in_array($tcaFieldName, $GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns'])) {
                    continue;
                }
                // Skip if no default value is defined in the accordant TCA definition (NULL values might occur as well)
                if (empty($tcaFieldConfiguration['config']) || !array_key_exists('default', $tcaFieldConfiguration['config'])) {
                    continue;
                }

                $data[$tableName]['fields'][] = $tcaFieldName;
                foreach ($data[$tableName]['elements'] as &$element) {
                    $element[$tcaFieldName] = $tcaFieldConfiguration['config']['default'];
                }
            }
        }
        return $data;
    }
727918
public function setValues($data)
    {
        if (!is_array($data)) {
            return $this;
        }

        foreach ($data as $key => $value) {
            $this->$key = $value;
        }
    }
238970
protected function validate(array &$data)
    {
        $messages = [];
        if (!empty($data['errors']) && !empty($data['activity']) && !empty($data['requests'])) {
            array_push($messages, ['warning', trans('It is recommended to periodically clean system logs.')]);
        }
        $data = array_merge($data, ['messages' => $messages]);
        return $data;
    }
348755
protected function _value($data)
    {
        $field = $this->config('name');
        $value = $data[$field];
        if (empty($value) && $this->_defaultDefined()) {
            $value = $this->config('default');
        }

        return $value;
    }
1007794
private function getValues(&$data) {
        $values = [];
        foreach ($data as $i => $row) {
            $skipImport = isset($this->skipImport) ? call_user_func($this->skipImport, $row) : false;
            if (!$skipImport) {
                foreach ($this->configs as $config) {
                    $value = call_user_func($config['value'], $row);
                    $values[$i][$config['attribute']] = $value;
                }
            }
        }
        //Filter unique values by unique attributes
        $values = $this->filterUniqueValues($values);
        return $values;
    }
746464
protected function decorateFieldData(array $data)
    {
        // Get the key-reference pairs to allow the form to display values for the
        // currently selected keys for the model.

        $keys = $data['value'] ?: [];

        if ($keys instanceof Arrayable) {
            $keys = $keys->toArray();
        }

        $data['references'] = $this->getReferencesForModelKeys(array_keys($keys));

        return $data;
    }
164002
protected function validate(array &$data, array $fields = [], bool $filter_before_validate = true, array $skip = [])
    {
        static $validator;

        if (empty($fields)) {

            // No and no fields in scheme means no validation rules so we have nothing to du here
            if (empty($this->scheme['fields'])) {
                return $data;
            }

            // Use the fields list from existing scheme
            $fields = $this->scheme['fields'];
        }

        // Still no fields?
        if (empty($fields)) {
            return $data;
        }

        // Lets run our rules
        foreach ($data as $key => $val) {

            // Is this field inside the $skip array list?
            if (in_array($key, $skip)) {
                continue;
            }

            // Run possible filters before the validation process
            if ($filter_before_validate && !empty($fields[$key]['filter'])) {

                if (!is_array($fields[$key]['filter'])) {
                    $fields[$key]['filter'] = (array) $fields[$key]['filter'];
                }

                foreach ($fields[$key]['filter'] as $filter) {

                    $options = [];

                    if (is_array($filter)) {
                        $options = $filter[1];
                        $filter = $filter[0];
                    }

                    $result = filter_var($val, $filter, $options);

                    if ($result === false) {
                        $this->addError($key, sprintf($this->app->language->get('validator.filter'), $filter));
                    }
                    else {
                        $data[$key] = $result;
                    }
                }
            }

            if (empty($fields[$key]['validate'])) {
                continue;
            }

            if (empty($validator)) {
                $validator = new Validator();
            }

            if (!is_array($fields[$key]['validate'])) {
                $fields[$key]['validate'] = (array) $fields[$key]['validate'];
            }

            $validator->setValue($val);

            foreach ($fields[$key]['validate'] as $rule) {

                $validator->parseRule($rule);
                $validator->validate();

                if (!$validator->isValid()) {

                    $result = $validator->getResult();

                    if (is_array($result)) {
                        $result = vsprintf($this->app->language->get($result[0]), $result[1]);
                    }
                    else {
                        $result = $this->app->language->get($result);
                    }

                    $this->errors[$key][] = $result;
                }
            }
        }

        return $data;
    }