Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(next): next_entity_type_config dependencies #620

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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());
}

}
Loading