diff --git a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php index e06c985..b46ce28 100644 --- a/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php +++ b/core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php @@ -2,9 +2,12 @@ namespace Drupal\image\Plugin\Field\FieldWidget; +use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemListInterface; +use Drupal\Core\Image\ImageFactory; use Drupal\Component\Utility\NestedArray; use Drupal\Core\Form\FormStateInterface; +use Drupal\Core\Render\ElementInfoManagerInterface; use Drupal\file\Entity\File; use Drupal\file\Plugin\Field\FieldWidget\FileWidget; use Drupal\image\Entity\ImageStyle; @@ -30,6 +33,29 @@ class ImageWidget extends FileWidget { protected $imageFactory; /** + * Constructs an ImageWidget object. + * + * @param string $plugin_id + * The plugin_id for the widget. + * @param mixed $plugin_definition + * The plugin implementation definition. + * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition + * The definition of the field to which the widget is associated. + * @param array $settings + * The widget settings. + * @param array $third_party_settings + * Any third party settings. + * @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info + * The element info manager service. + * @param \Drupal\Core\Image\ImageFactory $image_factory + * The image factory service. + */ + public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, array $third_party_settings, ElementInfoManagerInterface $element_info, ImageFactory $image_factory = NULL) { + parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $third_party_settings, $element_info); + $this->imageFactory = $image_factory; + } + + /** * {@inheritdoc} */ public static function defaultSettings() { @@ -333,12 +359,15 @@ public function onDependencyRemoval(array $dependencies) { * @return \Drupal\Core\Image\ImageFactory * The image factory service. * - * @todo Replace this method with proper service injection in 9.0.x. + * @deprecated in Drupal 8.4.x, will be removed before Drupal 9.0.0. + * Use injected service instead. + * + * @todo Replace this method with proper service injection in 9.0.0. * * @internal */ protected function getImageFactory() { - if (!isset($this->imageFactory)) { + if (!$this->imageFactory) { $this->imageFactory = \Drupal::service('image.factory'); } return $this->imageFactory;