getBundleConfigDependency example

parent::preSave($storage);
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    $target_entity_type = $this->entityTypeManager()->getDefinition($this->targetEntityType);

    // Create dependency on the bundle.     $bundle_config_dependency = $target_entity_type->getBundleConfigDependency($this->bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    // If field.module is enabled, add dependencies on 'field_config' entities     // for both displayed and hidden fields. We intentionally leave out base     // field overrides, since the field still exists without them.     if (\Drupal::moduleHandler()->moduleExists('field')) {
      $components = $this->content + $this->hidden;
      $field_definitions = \Drupal::service('entity_field.manager')->getFieldDefinitions($this->targetEntityType, $this->bundle);
      foreach (array_intersect_key($field_definitions$components) as $field_definition) {
        if ($field_definition instanceof ConfigEntityInterface && $field_definition->getEntityTypeId() == 'field_config') {
          $this->addDependency('config', $field_definition->getConfigDependencyName());
        }
return $config;
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();

    // Create dependency on the bundle.     $entity_type = \Drupal::entityTypeManager()->getDefinition($this->target_entity_type_id);
    $bundle_config_dependency = $entity_type->getBundleConfigDependency($this->target_bundle);
    $this->addDependency($bundle_config_dependency['type']$bundle_config_dependency['name']);

    return $this;
  }

}

  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    foreach ($this->getEntityTypes() as $entity_type_id) {
      $entity_definition = $this->entityTypeManager->getDefinition($entity_type_id);
      foreach ($this->getBundlesForEntityType($entity_type_id) as $bundle) {
        $dependency = $entity_definition->getBundleConfigDependency($bundle);
        $dependencies[$dependency['type']][] = $dependency['name'];
      }
    }
    return $dependencies;
  }

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

    
$definition = $field_type_manager->getDefinition($this->getType());
    $this->addDependency('module', $definition['provider']);
    // Plugins can declare additional dependencies in their definition.     if (isset($definition['config_dependencies'])) {
      $this->addDependencies($definition['config_dependencies']);
    }
    // Let the field type plugin specify its own dependencies.     // @see \Drupal\Core\Field\FieldItemInterface::calculateDependencies()     $this->addDependencies($definition['class']::calculateDependencies($this));

    // 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');
    
Home | Imprint | This part of the site doesn't use cookies.