diff --git a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php index fbc30d8..4dc6120 100644 --- a/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php +++ b/core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php @@ -46,7 +46,7 @@ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInter * {@inheritdoc} */ public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static($plugin_id, $plugin_definition,$configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container->get('element_info')); + return new static($plugin_id, $plugin_definition, $configuration['field_definition'], $configuration['settings'], $configuration['third_party_settings'], $container->get('element_info')); } /** diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index f202293..b941fe6 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -7,11 +7,15 @@ namespace Drupal\image\Plugin\Field\FieldWidget; -use Drupal\Core\Field\FieldItemListInterface; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Field\FieldDefinitionInterface; +use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Image\ImageFactory; +use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\file\Entity\File; use Drupal\file\Plugin\Field\FieldWidget\FileWidget; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * Plugin implementation of the 'image_image' widget. @@ -29,6 +33,29 @@ class ImageWidget extends FileWidget { /** * {@inheritdoc} */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info, ImageFactory $image_factory) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info); + $this->imageFactory = $image_factory; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['third_party_settings'], + $container->get('element_info'), + $container->get('image.factory') + ); + } + + /** + * {@inheritdoc} + */ public static function defaultSettings() { return array( 'progress_indicator' => 'throbber', @@ -121,8 +148,8 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element['#upload_validators']['file_validate_image_resolution'] = array($field_settings['max_resolution'], $field_settings['min_resolution']); } - // If not using custom extension validation, ensure this is an image. - $supported_extensions = array('png', 'gif', 'jpg', 'jpeg'); + // If not using custom extension validation, ensure this is a supported image. + $supported_extensions = $this->imageFactory->getSupportedExtensions(); $extensions = isset($element['#upload_validators']['file_validate_extensions'][0]) ? $element['#upload_validators']['file_validate_extensions'][0] : implode(' ', $supported_extensions); $extensions = array_intersect(explode(' ', $extensions), $supported_extensions); $element['#upload_validators']['file_validate_extensions'][0] = implode(' ', $extensions); diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index d16330f..2da5dea 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -347,7 +347,16 @@ public static function isAvailable() { public static function getSupportedExtensions() { $extensions = array(); foreach (static::supportedTypes() as $image_type) { - $extensions[] = Unicode::strtolower(image_type_to_extension($image_type, FALSE)); + $extension = Unicode::strtolower(image_type_to_extension($image_type, FALSE)); + $extensions[] = $extension; + // Add some known similar extensions. + // @todo Figure out how to handle this better. + if ($extension === 'jpeg') { + $extensions[] = 'jpg'; + } + elseif ($extension === 'tiff') { + $extensions[] = 'tif'; + } } return $extensions; }