summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarpad.rozsa2018-12-28 02:27:46 (GMT)
committerEmil Stjerneman2018-12-28 02:27:46 (GMT)
commit3b5b286c510d77a7c2d05165253a1563ae464dff (patch)
treedd7b9e6037bb8c4a7c6e5b1b92a67aba130fb6db
parent1ff6c1cbdbe6197e0a3bb44e5be2c63ebfdf6849 (diff)
Issue #3018705 by arpad.rozsa: FileMatcher checks image information if not needed and for non-image files
-rw-r--r--src/Plugin/Linkit/Matcher/FileMatcher.php40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/Plugin/Linkit/Matcher/FileMatcher.php b/src/Plugin/Linkit/Matcher/FileMatcher.php
index 28252a2..9d05089 100644
--- a/src/Plugin/Linkit/Matcher/FileMatcher.php
+++ b/src/Plugin/Linkit/Matcher/FileMatcher.php
@@ -190,22 +190,30 @@ class FileMatcher extends EntityMatcher {
/** @var \Drupal\file\FileInterface $entity */
$file = $entity->getFileUri();
- /** @var \Drupal\Core\Image\ImageInterface $image */
- $image = \Drupal::service('image.factory')->get($file);
- if ($image->isValid()) {
- if ($this->configuration['images']['show_dimensions']) {
- $description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px';
- }
-
- if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) {
- $image_element = [
- '#weight' => -10,
- '#theme' => 'image_style',
- '#style_name' => $this->configuration['images']['thumbnail_image_style'],
- '#uri' => $entity->getFileUri(),
- ];
-
- $description_array[] = (string) \Drupal::service('renderer')->render($image_element);
+ if ($this->configuration['images']['show_dimensions'] || $this->configuration['images']['show_thumbnail']) {
+ $image_factory = \Drupal::service('image.factory');
+ $supported_extensions = $image_factory->getSupportedExtensions();
+
+ // Check if the file extension is supported by the image toolkit.
+ if (empty(file_validate_extensions($entity, implode(' ', $supported_extensions)))) {
+ /** @var \Drupal\Core\Image\ImageInterface $image */
+ $image = $image_factory->get($file);
+ if ($image->isValid()) {
+ if ($this->configuration['images']['show_dimensions']) {
+ $description_array[] = $image->getWidth() . 'x' . $image->getHeight() . 'px';
+ }
+
+ if ($this->configuration['images']['show_thumbnail'] && $this->moduleHandler->moduleExists('image')) {
+ $image_element = [
+ '#weight' => -10,
+ '#theme' => 'image_style',
+ '#style_name' => $this->configuration['images']['thumbnail_image_style'],
+ '#uri' => $entity->getFileUri(),
+ ];
+
+ $description_array[] = (string) \Drupal::service('renderer')->render($image_element);
+ }
+ }
}
}