public function SvgImageWidget::onDependencyRemoval in Svg Image 2.x
Same name and namespace in other branches
- 8 src/Plugin/Field/FieldWidget/SvgImageWidget.php \Drupal\svg_image\Plugin\Field\FieldWidget\SvgImageWidget::onDependencyRemoval()
- 1.x src/Plugin/Field/FieldWidget/SvgImageWidget.php \Drupal\svg_image\Plugin\Field\FieldWidget\SvgImageWidget::onDependencyRemoval()
Informs the plugin that some configuration it depends on will be deleted.
This method allows plugins to keep their configuration up-to-date when a dependency calculated with ::calculateDependencies() is removed. For example, an entity view display contains a formatter having a setting pointing to an arbitrary config entity. When that config entity is deleted, this method is called by the view display to react to the dependency removal by updating its configuration.
This method must return TRUE if the removal event updated the plugin configuration or FALSE otherwise.
Parameters
array $dependencies: An array of dependencies that will be deleted keyed by dependency type. Dependency types are 'config', 'content', 'module' and 'theme'.
Return value
bool TRUE if the plugin configuration has changed, FALSE if not.
Overrides PluginSettingsBase::onDependencyRemoval
See also
\Drupal\Core\Entity\EntityDisplayBase
File
- src/
Plugin/ Field/ FieldWidget/ SvgImageWidget.php, line 347
Class
- SvgImageWidget
- Override plugin of the 'image_image' widget.
Namespace
Drupal\svg_image\Plugin\Field\FieldWidgetCode
public function onDependencyRemoval(array $dependencies) {
$changed = parent::onDependencyRemoval($dependencies);
$styleId = $this
->getSetting('preview_image_style');
/** @var \Drupal\image\ImageStyleInterface $style */
if ($styleId) {
$style = $this->imageStyleStorage
->load($styleId);
if ($style) {
if (!empty($dependencies[$style
->getConfigDependencyKey()][$style
->getConfigDependencyName()])) {
/** @var \Drupal\image\ImageStyleStorageInterface $storage */
$storage = $this->entityTypeManager
->getStorage($style
->getEntityTypeId());
$replacementId = $storage
->getReplacementId($styleId);
// If a valid replacement has been provided in the storage, replace
// the preview image style with the replacement.
if ($replacementId && $this->imageStyleStorage
->load($replacementId)) {
$this
->setSetting('preview_image_style', $replacementId);
}
else {
$this
->setSetting('preview_image_style', '');
}
// Signal that the formatter plugin settings were updated.
$changed = TRUE;
}
}
}
return $changed;
}