function ImageWidget::onDependencyRemoval

Same name in other branches
  1. 8.9.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::onDependencyRemoval()
  2. 10 core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::onDependencyRemoval()
  3. 11.x core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php \Drupal\image\Plugin\Field\FieldWidget\ImageWidget::onDependencyRemoval()

Overrides PluginSettingsBase::onDependencyRemoval

File

core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php, line 320

Class

ImageWidget
Plugin implementation of the 'image_image' widget.

Namespace

Drupal\image\Plugin\Field\FieldWidget

Code

public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    $style_id = $this->getSetting('preview_image_style');
    
    /** @var \Drupal\image\ImageStyleInterface $style */
    if ($style_id && ($style = ImageStyle::load($style_id))) {
        if (!empty($dependencies[$style->getConfigDependencyKey()][$style->getConfigDependencyName()])) {
            
            /** @var \Drupal\image\ImageStyleStorageInterface $storage */
            $storage = \Drupal::entityTypeManager()->getStorage($style->getEntityTypeId());
            $replacement_id = $storage->getReplacementId($style_id);
            // If a valid replacement has been provided in the storage, replace the
            // preview image style with the replacement.
            if ($replacement_id && ImageStyle::load($replacement_id)) {
                $this->setSetting('preview_image_style', $replacement_id);
            }
            else {
                $this->setSetting('preview_image_style', '');
            }
            // Signal that the formatter plugin settings were updated.
            $changed = TRUE;
        }
    }
    return $changed;
}

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