getConfigDependencyName example

private function buildBundlePermission(EntityTypeInterface $entity_type, string $bundle, array $bundle_info) {
    $permission = [
      'title' => $this->t('Translate %bundle_label @entity_label', [
        '@entity_label' => $entity_type->getSingularLabel(),
        '%bundle_label' => $bundle_info['label'] ?? $bundle,
      ]),
    ];

    // If the entity type uses bundle entities, add a dependency on the bundle.     $bundle_entity_type = $entity_type->getBundleEntityType();
    if ($bundle_entity_type && $bundle_entity = $this->entityTypeManager->getStorage($bundle_entity_type)->load($bundle)) {
      $permission['dependencies'][$bundle_entity->getConfigDependencyKey()][] = $bundle_entity->getConfigDependencyName();
    }
    else {
      $permission['dependencies']['module'][] = $entity_type->getProvider();
    }
    return $permission;
  }

}


  /** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();
    if ($mode = $this->getSetting('view_mode')) {
      if ($bundle = $this->getFieldSetting('comment_type')) {
        /** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display */
        if ($display = EntityViewDisplay::load("comment.$bundle.$mode")) {
          $dependencies[$display->getConfigDependencyKey()][] = $display->getConfigDependencyName();
        }
      }
    }
    return $dependencies;
  }

  /** * Provides a list of comment view modes for the configured comment type. * * @return array * Associative array keyed by view mode key and having the view mode label * as value. */
    $block_placement_id = mb_strtolower($block->label());
    $instance = [
      'id' => $block_placement_id,
      'settings[label]' => $block->label(),
      'region' => 'sidebar_first',
    ];
    $block = BlockContent::load(1);
    $url = 'admin/structure/block/add/block_content:' . $block->uuid() . '/' . $this->config('system.theme')->get('default');
    $this->drupalGet($url);
    $this->submitForm($instance, 'Save block');

    $dependencies = \Drupal::service('config.manager')->findConfigEntityDependenciesAsEntities('content', [$block->getConfigDependencyName()]);
    $block_placement = reset($dependencies);
    $this->assertEquals($block_placement_id$block_placement->id(), "The block placement config entity has a dependency on the block content entity.");
  }

}


  /** * Tests dependencies are not added for terms that do not exist. */
  public function testConfigDependency() {
    /** @var \Drupal\views\Entity\View $view */
    $view = View::load('test_filter_taxonomy_index_tid__non_existing_dependency');

    // Dependencies are sorted.     $content_dependencies = [
      $this->terms[3]->getConfigDependencyName(),
      $this->terms[4]->getConfigDependencyName(),
    ];
    sort($content_dependencies);

    $this->assertEquals([
      'config' => [
        'taxonomy.vocabulary.tags',
      ],
      'content' => $content_dependencies,
      'module' => [
        'node',
        
/** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    $view_mode = $this->entityTypeManager
      ->getStorage('entity_view_mode')
      ->load($this->entityTypeId . '.' . $this->options['view_mode']);
    if ($view_mode) {
      $dependencies[$view_mode->getConfigDependencyKey()][] = $view_mode->getConfigDependencyName();
    }

    return $dependencies;
  }

}
// Update a configuration entity in the sync directory to have a dependency     // on two content entities that do not exist.     $storage = $this->container->get('config.storage');
    $sync = $this->container->get('config.storage.sync');
    $entity_one = EntityTest::create(['name' => 'one']);
    $entity_two = EntityTest::create(['name' => 'two']);
    $entity_three = EntityTest::create(['name' => 'three']);
    $dynamic_name = 'config_test.dynamic.dotted.default';
    $original_dynamic_data = $storage->read($dynamic_name);
    // Entity one will be resolved by     // \Drupal\config_import_test\EventSubscriber::onConfigImporterMissingContentOne().     $original_dynamic_data['dependencies']['content'][] = $entity_one->getConfigDependencyName();
    // Entity two will be resolved by     // \Drupal\config_import_test\EventSubscriber::onConfigImporterMissingContentTwo().     $original_dynamic_data['dependencies']['content'][] = $entity_two->getConfigDependencyName();
    // Entity three will be resolved by     // \Drupal\Core\Config\Importer\FinalMissingContentSubscriber.     $original_dynamic_data['dependencies']['content'][] = $entity_three->getConfigDependencyName();
    $sync->write($dynamic_name$original_dynamic_data);

    // Import.     $this->configImporter->reset()->import();
    $this->assertEquals([]$this->configImporter->getErrors(), 'There were no errors during the import.');
    
    // https://www.drupal.org/project/drupal/issues/2945635.     throw new \BadMethodCallException('Method not supported');
  }

  /** * Gets typed data for config entity. * * @return \Drupal\Core\TypedData\ComplexDataInterface * The typed data. */
  protected function getConfigTypedData() {
    return $this->getTypedConfigManager()->createFromNameAndData($this->entity->getConfigDependencyName()$this->entity->toArray());
  }

}
public function permissions() {
    $permissions = [];
    /** @var \Drupal\rest\RestResourceConfigInterface[] $resource_configs */
    $resource_configs = $this->resourceConfigStorage->loadMultiple();
    foreach ($resource_configs as $resource_config) {
      $plugin = $resource_config->getResourcePlugin();

      // Add the rest resource configuration entity as a dependency to the       // permissions.       $permissions += array_map(function Darray $permission_info) use ($resource_config) {
        $merge_info['dependencies'][$resource_config->getConfigDependencyKey()] = [
          $resource_config->getConfigDependencyName(),
        ];
        return NestedArray::mergeDeep($permission_info$merge_info);
      }$plugin->permissions());
    }
    return $permissions;
  }

}
\Drupal::service('state')->set('config_test.lookup_keys', TRUE);
    \Drupal::entityTypeManager()->clearCachedDefinitions();
    $key_value = $this->container->get('keyvalue')->get(QueryFactory::CONFIG_LOOKUP_PREFIX . 'config_test');

    $test_entities = [];
    $storage = \Drupal::entityTypeManager()->getStorage('config_test');
    $entity = $storage->create([
      'label' => 'entity_1',
      'id' => '1',
      'style' => 'test',
    ]);
    $test_entities[$entity->getConfigDependencyName()] = $entity;
    $entity->enforceIsNew();
    $entity->save();

    $expected[] = $entity->getConfigDependencyName();
    $this->assertEquals($expected$key_value->get('style:test'));

    $entity = $storage->create([
      'label' => 'entity_2',
      'id' => '2',
      'style' => 'test',
    ]);
    
/** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    if ($this->entityTypeManager->hasDefinition('block_content_type')) {
      $block_content_types = $this->entityTypeManager->getStorage('block_content_type')->loadMultiple();
      foreach ($block_content_types as $id => $type) {
        $this->derivatives[$id] = $base_plugin_definition;
        $this->derivatives[$id]['admin_label'] = $type->label();
        $this->derivatives[$id]['config_dependencies'][$type->getConfigDependencyKey()][] = $type->getConfigDependencyName();
      }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

  private function getDependentConfigNames() {
    $modules = $this->getExcludedModules();

    $dependencyManager = $this->manager->getConfigDependencyManager();
    $config = [];

    // Find all the configuration depending on the excluded modules.     foreach ($modules as $module) {
      foreach ($dependencyManager->getDependentEntities('module', $module) as $dependent) {
        $config[] = $dependent->getConfigDependencyName();
      }
      $config = array_merge($config$this->activeStorage->listAll($module . '.'));
    }

    // Find all configuration that depends on the configuration found above.     foreach ($this->manager->findConfigEntityDependencies('config', array_unique($config)) as $dependent) {
      $config[] = $dependent->getConfigDependencyName();
    }

    return array_unique($config);
  }

}
$this->assertSame('config_test.validation', $typed_config->getName());
    $this->assertSame('config_test.validation', $typed_config->getPropertyPath());
    $this->assertSame('config_test.validation.llama', $typed_config->get('llama')->getPropertyPath());

    $config_test_entity = \Drupal::entityTypeManager()->getStorage('config_test')->create([
      'id' => 'asterix',
      'label' => 'Asterix',
      'weight' => 11,
      'style' => 'test_style',
    ]);

    $typed_config = $typed_config_manager->createFromNameAndData($config_test_entity->getConfigDependencyName()$config_test_entity->toArray());
    $this->assertInstanceOf(TypedConfigInterface::class$typed_config);
    $this->assertEquals(['uuid', 'langcode', 'status', 'dependencies', 'id', 'label', 'weight', 'style', 'size', 'size_value', 'protected_property']array_keys($typed_config->getElements()));
  }

  /** * Tests config validation via the Typed Data API. */
  public function testSimpleConfigValidation() {
    $config = \Drupal::configFactory()->getEditable('config_test.validation');
    /** @var \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager */
    $typed_config_manager = \Drupal::service('config.typed');
    
/** * {@inheritdoc} */
  public function calculateDependencies() {
    $dependencies = parent::calculateDependencies();

    // Ensure that we don't add dependencies for placeholders.     // @todo Use a method to check for tokens in     // https://www.drupal.org/node/2396607.     if (!str_contains($this->options['target'], '{{')) {
      if ($entity = $this->entityRepository->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
        $dependencies[$this->entityTypeManager->getDefinition($this->entityType)->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
      }
    }

    return $dependencies;
  }

}
'format' => 'dummy',
      'name' => 'Dummy',
    ])->save();
    $editor = Editor::create([
      'format' => 'dummy',
      'editor' => 'ckeditor5',
      'settings' => $ckeditor5_settings,
      'image_upload' => [],
    ]);

    $typed_config = $this->typedConfig->createFromNameAndData(
      $editor->getConfigDependencyName(),
      $editor->toArray(),
    );
    $violations = $typed_config->validate();

    $actual_violations = [];
    foreach ($violations as $violation) {
      $actual_violations[$violation->getPropertyPath()] = (string) $violation->getMessage();
    }
    $this->assertSame($expected_violations$actual_violations);

    if (empty($expected_violations)) {
      

  public function label() {
    return $this->getFilterFormat()->label();
  }

  /** * {@inheritdoc} */
  public function calculateDependencies() {
    parent::calculateDependencies();
    // Create a dependency on the associated FilterFormat.     $this->addDependency('config', $this->getFilterFormat()->getConfigDependencyName());
    // @todo use EntityWithPluginCollectionInterface so configuration between     // config entity and dependency on provider is managed automatically.     $definition = $this->editorPluginManager()->createInstance($this->editor)->getPluginDefinition();
    $this->addDependency('module', $definition['provider']);
    return $this;
  }

  /** * {@inheritdoc} */
  public function hasAssociatedFilterFormat() {
    
Home | Imprint | This part of the site doesn't use cookies.