Skip to content
Snippets Groups Projects

wrapped file_validate_extensions in deprecationhelper with new >=10.2 equivalent

@@ -2,6 +2,7 @@
namespace Drupal\linkit\Plugin\Linkit\Matcher;
use Drupal\Component\Utility\DeprecationHelper;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\FileInterface;
@@ -194,9 +195,21 @@ class FileMatcher extends EntityMatcher {
if ($this->configuration['images']['show_dimensions'] || $this->configuration['images']['show_thumbnail']) {
$image_factory = \Drupal::service('image.factory');
$supported_extensions = $image_factory->getSupportedExtensions();
/** @var \Drupal\file\Validation\FileValidatorInterface $file_validator */
$file_validator = \Drupal::service('file.validator');
$validators = ['FileExtension' => ['extensions' => $supported_extensions]];
// Check if the file extension is supported by the image toolkit.
if (empty(file_validate_extensions($entity, implode(' ', $supported_extensions)))) {
$result = DeprecationHelper::backwardsCompatibleCall(
\Drupal::VERSION,
'10.2',
static function ($file, $file_validator, $validators) {
return $file_validator->validate($file, $validators);
},
static function ($entity, $supported_extensions) {
return file_validate_extensions($entity, implode(' ', $supported_extensions));
}
);
if (empty($result)) {
/** @var \Drupal\Core\Image\ImageInterface $image */
$image = $image_factory->get($file);
if ($image->isValid()) {
Loading