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
23 changes: 23 additions & 0 deletions modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,27 @@ 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',
],
],
]);
self::assertEquals([], $entity_type_config->getDependencies());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I misreading this assertion?

If the purpose of calculateDependencies() is to add the proper dependencies to the config, why is the test asserting that getDependencies() is an empty array? How does this test that dependencies are added properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I can't remember if I left this here to show the test was still failing or what... Or if I wrote the test first and then the fix?

I'll follow back up on this today

}

}
Loading