- Issue created by @hkirsman
- πͺπͺEstonia hkirsman
1. What is this talk about PHP 5.3? I did find it was added 13 years ago https://git.drupalcode.org/project/filefield_sources/-/commit/57a0d0a643...
I think this might be replaced by what is in file.module2. All t() functions return object so doing .= will fail.
3. $file->filename is not string but but object. I think something like $file->getFileName() should be used.
/** * Validate a file based on the $element['#upload_validators'] property. */ function filefield_sources_element_validate($element, $file, FormStateInterface $form_state) { $validators = $element['#upload_validators']; $errors = []; // Since this frequently is used to reference existing files, check that // they exist first in addition to the normal validations. if (!file_exists($file->getFileUri())) { $errors[] = t('The file does not exist.'); } // Call the validation functions. else { foreach ($validators as $function => $args) { // Add the $file variable to the list of arguments and pass it by // reference (required for PHP 5.3 and higher). array_unshift($args, NULL); $args[0] = &$file; $errors = array_merge($errors, call_user_func_array($function, $args)); } } // Check for validation errors. if (!empty($errors)) { $message = t('The selected file %name could not be referenced.', ['%name' => $file->filename]); if (count($errors) > 1) { $message .= '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>'; } else { $message .= ' ' . array_pop($errors); } $form_state->setError($element, $message); return 0; } return 1; }
- Status changed to Closed: duplicate
9 months ago 11:23pm 22 April 2024 - πΊπΈUnited States rschwab
Closing as a duplicate of π Make sure $callback is_callable. ( TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, function "FileSizeLimit" not found or invalid function name ) Needs review . There are two different solutions there that need community review.