Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions modules/next/src/Entity/NextEntityTypeConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,20 @@ public function getPluginCollections() {
return $collections;
}

/**
* {@inheritdoc}
*
* @todo add sites with onDependencyRemoval support.
*/
public function calculateDependencies() {
parent::calculateDependencies();
[$entity_type_id, $bundle] = explode('.', $this->id());
$target_entity_type = $this->entityTypeManager()->getDefinition($entity_type_id);
$bundle_config_dependency = $target_entity_type->getBundleConfigDependency($bundle);
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
return $this;
}

/**
* Wraps the site_resolver plugin manager.
*
Expand Down
32 changes: 32 additions & 0 deletions modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Drupal\KernelTests\KernelTestBase;
use Drupal\next\Entity\NextEntityTypeConfig;
use Drupal\next\Entity\NextSite;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\node\Traits\NodeCreationTrait;

/**
Expand Down Expand Up @@ -43,6 +44,8 @@ protected function setUp(): void {
$this->installConfig(['filter']);
$this->installSchema('system', ['sequences']);
$this->installSchema('node', ['node_access']);

NodeType::create(['type' => 'page'])->save();
}

/**
Expand Down Expand Up @@ -140,4 +143,33 @@ public function testRevalidator() {
$this->assertSame('path', $revalidator->getId());
}

/**
* Tests config dependency calculation.
*/
public function testConfigDependencies(): void {
$blog_site = NextSite::create([
'id' => 'blog',
]);
$blog_site->save();

// Create entity type config.
/** @var \Drupal\next\Entity\NextEntityTypeConfigInterface $entity_type_config */
$entity_type_config = NextEntityTypeConfig::create([
'id' => 'node.page',
'site_resolver' => 'site_selector',
'configuration' => [
'sites' => [
'blog' => 'blog',
],
],
]);
// Saving causes dependency calculation.
$entity_type_config->save();
self::assertEquals([
'config' => [
'node.type.page',
],
], $entity_type_config->getDependencies());
}

}