diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php index b52c50e..278ebeb 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php @@ -8,7 +8,6 @@ namespace Drupal\image\Plugin\Field\FieldFormatter; use Drupal\Core\Field\FieldItemListInterface; -use Drupal\image\Entity\ImageStyle; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Url; @@ -143,41 +142,4 @@ public function viewElements(FieldItemListInterface $items, $langcode) { return $elements; } - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - $dependencies = parent::calculateDependencies(); - $style_id = $this->getSetting('image_style'); - /** @var \Drupal\image\ImageStyleInterface $style */ - if ($style_id && $style = ImageStyle::load($style_id)) { - // If this formatter uses a valid image style to display the image, add - // the image style configuration entity as dependency of this formatter. - $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName(); - } - return $dependencies; - } - - /** - * {@inheritdoc} - */ - public function onDependencyRemoval(array $dependencies) { - $changed = parent::onDependencyRemoval($dependencies); - $style_id = $this->getSetting('image_style'); - /** @var \Drupal\image\ImageStyleInterface $style */ - if ($style_id && $style = ImageStyle::load($style_id)) { - if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) { - $replacement_id = $this->imageStyleStorage->getReplacementId($style_id); - // If a valid replacement has been provided in the storage, replace the - // image style with the replacement and signal that the formatter plugin - // settings were updated. - if ($replacement_id && ImageStyle::load($replacement_id)) { - $this->setSetting('image_style', $replacement_id); - $changed = TRUE; - } - } - } - return $changed; - } - } diff --git a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php index 5100793..e54c4e1 100644 --- a/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php +++ b/core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatterBase.php @@ -18,6 +18,7 @@ use Drupal\Core\Url; use Drupal\field\FieldConfigInterface; use Drupal\file\Plugin\Field\FieldFormatter\FileFormatterBase; +use Drupal\image\Entity\ImageStyle; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -177,6 +178,43 @@ protected function getEntitiesToView(EntityReferenceFieldItemListInterface $item } /** + * {@inheritdoc} + */ + public function calculateDependencies() { + $dependencies = parent::calculateDependencies(); + $style_id = $this->getSetting('image_style'); + /** @var \Drupal\image\ImageStyleInterface $style */ + if ($style_id && $style = ImageStyle::load($style_id)) { + // If this formatter uses a valid image style to display the image, add + // the image style configuration entity as dependency of this formatter. + $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName(); + } + return $dependencies; + } + + /** + * {@inheritdoc} + */ + public function onDependencyRemoval(array $dependencies) { + $changed = parent::onDependencyRemoval($dependencies); + $style_id = $this->getSetting('image_style'); + /** @var \Drupal\image\ImageStyleInterface $style */ + if ($style_id && $style = ImageStyle::load($style_id)) { + if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) { + $replacement_id = $this->imageStyleStorage->getReplacementId($style_id); + // If a valid replacement has been provided in the storage, replace the + // image style with the replacement and signal that the formatter plugin + // settings were updated. + if ($replacement_id && ImageStyle::load($replacement_id)) { + $this->setSetting('image_style', $replacement_id); + $changed = TRUE; + } + } + } + return $changed; + } + + /** * Returns the entity repository service. * * @return \Drupal\Core\Entity\EntityRepositoryInterface