function TestFieldWidget::onDependencyRemoval

Same name in other branches
  1. 9 core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php \Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidget::onDependencyRemoval()
  2. 8.9.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php \Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidget::onDependencyRemoval()
  3. 11.x core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php \Drupal\field_test\Plugin\Field\FieldWidget\TestFieldWidget::onDependencyRemoval()

Overrides PluginSettingsBase::onDependencyRemoval

File

core/modules/field/tests/modules/field_test/src/Plugin/Field/FieldWidget/TestFieldWidget.php, line 99

Class

TestFieldWidget
Plugin implementation of the 'test_field_widget' widget.

Namespace

Drupal\field_test\Plugin\Field\FieldWidget

Code

public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    // Only the setting 'role' is resolved here. When the dependency related to
    // this setting is removed, is expected that the widget component will be
    // update accordingly in the display entity. The 'role2' setting is
    // deliberately left out from being updated. When the dependency
    // corresponding to this setting is removed, is expected that the widget
    // component will be disabled in the display entity.
    if (!empty($role_id = $this->getSetting('role'))) {
        if (!empty($dependencies['config']["user.role.{$role_id}"])) {
            $this->setSetting('role', 'anonymous');
            $changed = TRUE;
        }
    }
    return $changed;
}

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