onDependencyRemoval example

foreach ($dependencies as $dependency) {
        $this->addDependency($type$dependency);
      }
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $parent = parent::onDependencyRemoval($dependencies);

    // If the dependency problems are not marked as fixed at this point they     // should be related to the resource plugin and the config entity should     // be deleted.     $changed = $this->getRestResourceDependencies()->onDependencyRemoval($this$dependencies);
    return $parent || $changed;
  }

  /** * Returns the REST resource dependencies. * * @return \Drupal\rest\Entity\ConfigDependencies */
      if (!empty($permission_definitions[$permission]['dependencies'])) {
        $this->addDependencies($permission_definitions[$permission]['dependencies']);
      }
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    // Load all permission definitions.     $permission_definitions = \Drupal::service('user.permissions')->getPermissions();

    // Convert config and content entity dependencies to a list of names to make     // it easier to check.     foreach (['content', 'config'] as $type) {
      $dependencies[$type] = array_keys($dependencies[$type]);
    }

    // Remove any permissions from the role that are dependent on anything being     // deleted or uninstalled.
$this->calculatePluginDependencies($component->getPlugin());
      }
    }

    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);

    // Loop through all sections and determine if the removed dependencies are     // used by their layout plugins.     foreach ($this->getSections() as $delta => $section) {
      $layout_dependencies = $this->getPluginDependencies($section->getLayout());
      $layout_removed_dependencies = $this->getPluginRemovedDependencies($layout_dependencies$dependencies);
      if ($layout_removed_dependencies) {
        // @todo Allow the plugins to react to their dependency removal in         // https://www.drupal.org/project/drupal/issues/2579743.         $this->removeSection($delta);
        $changed = TRUE;
      }

  public function testCalculateDependenciesWithThirdPartySettings() {
    $this->entity = $this->getMockForAbstractClass('\Drupal\Core\Config\Entity\ConfigEntityBase', [[]$this->entityTypeId]);
    $this->entity->setThirdPartySetting('test_provider', 'test', 'test');
    $this->entity->setThirdPartySetting('test_provider2', 'test', 'test');
    $this->entity->setThirdPartySetting($this->provider, 'test', 'test');

    $this->assertEquals(['test_provider', 'test_provider2']$this->entity->calculateDependencies()->getDependencies()['module']);
    $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider2']]);
    $this->assertTrue($changed, 'Calling onDependencyRemoval with an existing third party dependency provider returns TRUE.');
    $changed = $this->entity->onDependencyRemoval(['module' => ['test_provider3']]);
    $this->assertFalse($changed, 'Calling onDependencyRemoval with a non-existing third party dependency provider returns FALSE.');
    $this->assertEquals(['test_provider']$this->entity->calculateDependencies()->getDependencies()['module']);
  }

  /** * @covers ::__sleep */
  public function testSleepWithPluginCollections() {
    $instance_id = 'the_instance_id';
    
'dependencies' => [
        'module' => [
          'fruiter',
        ],
      ],
      'third_party_settings' => [
        'fruiter' => [
          'fruit' => 'apple',
        ],
      ],
    ]);
    $changed = $field->onDependencyRemoval(['module' => ['fruiter']]);
    $this->assertTrue($changed);
  }

  /** * @covers ::toArray */
  public function testToArray() {
    $field = new FieldConfig([
      'field_name' => $this->fieldStorage->getName(),
      'entity_type' => 'test_entity_type',
      'bundle' => 'test_bundle',
      
/** * {@inheritdoc} */
  public function getConfigTarget() {
    return $this->storage->getConfigTarget();
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    return $this->storage->onDependencyRemoval($dependencies);
  }

  /** * {@inheritdoc} */
  public function getDependencies() {
    return $this->storage->getDependencies();
  }

  /** * {@inheritdoc} */
// Create dependency on the bundle.     $bundle_config_dependency = $this->entityTypeManager()->getDefinition($this->entity_type)->getBundleConfigDependency($this->bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    return $this;
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    $field_type_manager = \Drupal::service('plugin.manager.field.field_type');
    $definition = $field_type_manager->getDefinition($this->getType());
    if ($definition['class']::onDependencyRemoval($this$dependencies)) {
      $changed = TRUE;
    }
    return $changed;
  }

  /** * {@inheritdoc} */
  
      // uploaded image, add that image style configuration entity as dependency       // of this widget.       $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
    }
    return $dependencies;
  }

  /** * {@inheritdoc} */
  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);
        }
public static function calculateStorageDependencies(FieldStorageDefinitionInterface $field_definition) {
    $dependencies = parent::calculateStorageDependencies($field_definition);
    $target_entity_type = \Drupal::entityTypeManager()->getDefinition($field_definition->getSetting('target_type'));
    $dependencies['module'][] = $target_entity_type->getProvider();
    return $dependencies;
  }

  /** * {@inheritdoc} */
  public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies) {
    $changed = parent::onDependencyRemoval($field_definition$dependencies);
    $entity_type_manager = \Drupal::entityTypeManager();
    $target_entity_type = $entity_type_manager->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type'));

    // Try to update the default value config dependency, if possible.     if ($default_value = $field_definition->getDefaultValueLiteral()) {
      $entity_repository = \Drupal::service('entity.repository');
      foreach ($default_value as $key => $value) {
        if (is_array($value) && isset($value['target_uuid'])) {
          $entity = $entity_repository->loadEntityByUuid($target_entity_type->id()$value['target_uuid']);
          // @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()           if ($entity && isset($dependencies[$entity->getConfigDependencyKey()][$entity->getConfigDependencyName()])) {
            
// Key the entity arrays by config dependency name to make searching easy.     foreach (['config', 'content'] as $dependency_type) {
      $affected_dependencies[$dependency_type] = array_combine(
        array_map(function D$entity) {
          return $entity->getConfigDependencyName();
        }$affected_dependencies[$dependency_type]),
        $affected_dependencies[$dependency_type]
      );
    }

    // Inform the entity.     return $entity->onDependencyRemoval($affected_dependencies);
  }

  /** * {@inheritdoc} */
  public function findMissingContentDependencies() {
    $content_dependencies = [];
    $missing_dependencies = [];
    foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
      if (isset($config_data['dependencies']['content'])) {
        $content_dependencies[] = $config_data['dependencies']['content'];
      }
public function status() {
    // In order for a workflow to be usable it must have at least one state.     return !empty($this->status) && !empty($this->getTypePlugin()->getStates());
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    // Give the parent method and the workflow type plugin a chance to react     // to removed dependencies and report if either of these two made a change.     $parent_changed_entity = parent::onDependencyRemoval($dependencies);
    $plugin_changed_entity = $this->getTypePlugin()->onDependencyRemoval($dependencies);
    return $plugin_changed_entity || $parent_changed_entity;
  }

}

  private function fieldHasDisplayOptions(FieldDefinitionInterface $definition) {
    // The display only cares about fields that specify display options.     // Discard base fields that are not rendered through formatters / widgets.     return $definition->getDisplayOptions($this->displayContext);
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    foreach ($dependencies['config'] as $entity) {
      if ($entity->getEntityTypeId() == 'field_config') {
        // Remove components for fields that are being deleted.         $this->removeComponent($entity->getName());
        unset($this->hidden[$entity->getName()]);
        $changed = TRUE;
      }
    }
    foreach ($this->getComponents() as $name => $component) {
      if ($renderer = $this->getRenderer($name)) {
        if (in_array($renderer->getPluginDefinition()['provider']$dependencies['module'])) {
          

  public function removeFilter($instance_id) {
    unset($this->filters[$instance_id]);
    $this->filterCollection->removeInstanceId($instance_id);
  }

  /** * {@inheritdoc} */
  public function onDependencyRemoval(array $dependencies) {
    $changed = parent::onDependencyRemoval($dependencies);
    $filters = $this->filters();
    foreach ($filters as $filter) {
      // Remove disabled filters, so that this FilterFormat config entity can       // continue to exist.       if (!$filter->status && in_array($filter->provider, $dependencies['module'])) {
        $this->removeFilter($filter->getPluginId());
        $changed = TRUE;
      }
    }
    return $changed;
  }

  

  public function testOnDependencyRemovalRemoveUnrelatedDependency(array $configuration) {
    $config_dependencies = new ConfigDependencies(['json' => 'serialization']['basic_auth' => 'basic_auth']);

    $rest_config = RestResourceConfig::create($configuration);

    $this->assertFalse($config_dependencies->onDependencyRemoval($rest_config['module' => ['node']]));
    $this->assertEquals($configuration['configuration']$rest_config->get('configuration'));
  }

  /** * @return array * An array with numerical keys: * 0. The original REST resource configuration. */
  public function providerBasicDependencies() {
    return [
      'method' => [
        [
// If this formatter uses a valid image style to display the image, add       // the image style configuration entity as dependency of this formatter.       $dependencies[$style->getConfigDependencyKey()][] = $style->getConfigDependencyName();
    }
    return $dependencies;
  }

  /** * {@inheritdoc} */
  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;
        }
Home | Imprint | This part of the site doesn't use cookies.