You are here

public function DateRecurModularSierraWidget::onDependencyRemoval in Recurring Date Field Modular Widgets 8

Same name and namespace in other branches
  1. 3.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::onDependencyRemoval()
  2. 2.x src/Plugin/Field/FieldWidget/DateRecurModularSierraWidget.php \Drupal\date_recur_modular\Plugin\Field\FieldWidget\DateRecurModularSierraWidget::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/DateRecurModularSierraWidget.php, line 268

Class

DateRecurModularSierraWidget
Date recur sierra widget.

Namespace

Drupal\date_recur_modular\Plugin\Field\FieldWidget

Code

public function onDependencyRemoval(array $dependencies) : bool {
  $changed = parent::onDependencyRemoval($dependencies);
  $settings = $this
    ->getSettings();
  foreach ($dependencies['config'] ?? [] as $configDependency) {

    // Delete interpreter in settings if its being deleted.
    if ($configDependency instanceof DateRecurInterpreterInterface) {
      if ($settings['interpreter'] === $configDependency
        ->id()) {
        unset($settings['interpreter']);
        $this
          ->setSettings($settings);
        $changed = TRUE;
      }
    }
  }
  return $changed;
}