function ImageFormatter::onDependencyRemoval

Same name and namespace in other branches
  1. 9 core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::onDependencyRemoval()
  2. 10 core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::onDependencyRemoval()
  3. 11.x core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php \Drupal\image\Plugin\Field\FieldFormatter\ImageFormatter::onDependencyRemoval()

Overrides PluginSettingsBase::onDependencyRemoval

File

core/modules/image/src/Plugin/Field/FieldFormatter/ImageFormatter.php, line 256

Class

ImageFormatter
Plugin implementation of the 'image' formatter.

Namespace

Drupal\image\Plugin\Field\FieldFormatter

Code

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;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.