Grav\Plugin\Admin\AdminBaseController::normalizeFiles PHP Method

normalizeFiles() protected method

Internal method to normalize the $_FILES array
protected normalizeFiles ( array $data, string $key = '' ) : object
$data array $_FILES starting point data
$key string
return object a new Object with a normalized list of files
    protected function normalizeFiles($data, $key = '')
    {
        $files = new \stdClass();
        $files->field = $key;
        $files->file = new \stdClass();
        foreach ($data as $fieldName => $fieldValue) {
            // Since Files Upload are always happening via Ajax
            // we are not interested in handling `multiple="true"`
            // because they are always handled one at a time.
            // For this reason we normalize the value to string,
            // in case it is arriving as an array.
            $value = (array) Utils::getDotNotation($fieldValue, $key);
            $files->file->{$fieldName} = array_shift($value);
        }
        return $files;
    }