Skip to content

Commit ed7fdd2

Browse files
fix(next): next_entity_type_config dependencies (#620)
Co-authored-by: Bojan Bogdanovic <info@bojanbogdanovic.nl>
1 parent 95e7d7a commit ed7fdd2

11 files changed

Lines changed: 71 additions & 28 deletions

File tree

modules/next/modules/next_jsonapi/tests/src/Kernel/Controller/EntityResourceTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ protected function setUp(): void {
4747
$this->installConfig(['filter', 'next']);
4848
$this->installSchema('node', ['node_access']);
4949

50-
$type = NodeType::create([
51-
'type' => 'article',
52-
]);
53-
$type->save();
50+
NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
5451

5552
foreach (range(1, 100) as $number) {
5653
$article = $this->createNode([

modules/next/src/Entity/NextEntityTypeConfig.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,20 @@ public function getPluginCollections() {
255255
return $collections;
256256
}
257257

258+
/**
259+
* {@inheritdoc}
260+
*
261+
* @todo add sites with onDependencyRemoval support.
262+
*/
263+
public function calculateDependencies() {
264+
parent::calculateDependencies();
265+
[$entity_type_id, $bundle] = explode('.', $this->id());
266+
$target_entity_type = $this->entityTypeManager()->getDefinition($entity_type_id);
267+
$bundle_config_dependency = $target_entity_type->getBundleConfigDependency($bundle);
268+
$this->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
269+
return $this;
270+
}
271+
258272
/**
259273
* Wraps the site_resolver plugin manager.
260274
*

modules/next/tests/src/Kernel/Controller/NextPreviewUrlControllerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\KernelTests\KernelTestBase;
77
use Drupal\next\Controller\NextPreviewUrlController;
88
use Drupal\next\Entity\NextSite;
9+
use Drupal\node\Entity\NodeType;
910
use Drupal\Tests\node\Traits\NodeCreationTrait;
1011
use Drupal\Tests\user\Traits\UserCreationTrait;
1112
use Symfony\Component\HttpFoundation\Request;
@@ -44,6 +45,8 @@ protected function setUp(): void {
4445
$this->installConfig(['filter', 'next']);
4546
$this->installSchema('node', ['node_access']);
4647

48+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
49+
4750
$this->nextSite = NextSite::create([
4851
'label' => 'Blog',
4952
'id' => 'blog',

modules/next/tests/src/Kernel/Entity/NextEntityTypeConfigTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\KernelTests\KernelTestBase;
66
use Drupal\next\Entity\NextEntityTypeConfig;
77
use Drupal\next\Entity\NextSite;
8+
use Drupal\node\Entity\NodeType;
89
use Drupal\Tests\node\Traits\NodeCreationTrait;
910

1011
/**
@@ -42,6 +43,8 @@ protected function setUp(): void {
4243
$this->installEntitySchema('path_alias');
4344
$this->installConfig(['filter']);
4445
$this->installSchema('node', ['node_access']);
46+
47+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
4548
}
4649

4750
/**
@@ -169,4 +172,33 @@ public function testDraftEnabled() {
169172
$this->assertFalse($entity_type_config->isDraftEnabled());
170173
}
171174

175+
/**
176+
* Tests config dependency calculation.
177+
*/
178+
public function testConfigDependencies(): void {
179+
$blog_site = NextSite::create([
180+
'id' => 'blog',
181+
]);
182+
$blog_site->save();
183+
184+
// Create entity type config.
185+
/** @var \Drupal\next\Entity\NextEntityTypeConfigInterface $entity_type_config */
186+
$entity_type_config = NextEntityTypeConfig::create([
187+
'id' => 'node.page',
188+
'site_resolver' => 'site_selector',
189+
'configuration' => [
190+
'sites' => [
191+
'blog' => 'blog',
192+
],
193+
],
194+
]);
195+
// Saving causes dependency calculation.
196+
$entity_type_config->save();
197+
self::assertEquals([
198+
'config' => [
199+
'node.type.page',
200+
],
201+
], $entity_type_config->getDependencies());
202+
}
203+
172204
}

modules/next/tests/src/Kernel/Entity/NextSiteTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\KernelTests\KernelTestBase;
66
use Drupal\next\Entity\NextSite;
7+
use Drupal\node\Entity\NodeType;
78
use Drupal\Tests\node\Traits\NodeCreationTrait;
89
use Drupal\Tests\user\Traits\UserCreationTrait;
910
use Drupal\user\Entity\User;
@@ -42,6 +43,8 @@ protected function setUp(): void {
4243
$this->installConfig(['filter', 'next']);
4344
$this->installSchema('node', ['node_access']);
4445

46+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
47+
4548
$this->nextSite = NextSite::create([
4649
'label' => 'Blog',
4750
'id' => 'blog',

modules/next/tests/src/Kernel/Event/EntityRevalidatedEventTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\dblog\Controller\DbLogController;
66
use Drupal\KernelTests\KernelTestBase;
77
use Drupal\next\Entity\NextEntityTypeConfig;
8+
use Drupal\node\Entity\NodeType;
89
use Drupal\Tests\node\Traits\NodeCreationTrait;
910
use Symfony\Component\HttpFoundation\Request;
1011
use Symfony\Component\HttpFoundation\Response;
@@ -45,6 +46,8 @@ protected function setUp(): void {
4546
$this->installSchema('node', ['node_access']);
4647
$this->installSchema('user', ['users_data']);
4748

49+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
50+
4851
// Create entity type config.
4952
$entity_type_config = NextEntityTypeConfig::create([
5053
'id' => 'node.page',

modules/next/tests/src/Kernel/NextEntityTypeManagerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\KernelTests\KernelTestBase;
66
use Drupal\next\Entity\NextEntityTypeConfig;
77
use Drupal\next\Entity\NextSite;
8+
use Drupal\node\Entity\NodeType;
89
use Drupal\Tests\node\Traits\NodeCreationTrait;
910

1011
/**
@@ -33,6 +34,8 @@ protected function setUp(): void {
3334
$this->installEntitySchema('user');
3435
$this->installConfig(['filter', 'next']);
3536
$this->installSchema('node', ['node_access']);
37+
38+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
3639
}
3740

3841
/**

modules/next/tests/src/Kernel/Plugin/PathRevalidatorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Drupal\KernelTests\KernelTestBase;
66
use Drupal\next\Entity\NextEntityTypeConfig;
77
use Drupal\next\Entity\NextSite;
8+
use Drupal\node\Entity\NodeType;
89
use Drupal\Tests\node\Traits\NodeCreationTrait;
910
use GuzzleHttp\ClientInterface;
1011
use GuzzleHttp\Psr7\Response as GuzzleResponse;
@@ -48,6 +49,8 @@ protected function setUp(): void {
4849
$this->installEntitySchema('path_alias');
4950
$this->installConfig(['filter']);
5051
$this->installSchema('node', ['node_access']);
52+
53+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
5154
}
5255

5356
/**

modules/next/tests/src/Kernel/Plugin/SimpleOauthPreviewUrlGeneratorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Drupal\KernelTests\KernelTestBase;
77
use Drupal\next\Entity\NextEntityTypeConfig;
88
use Drupal\next\Entity\NextSite;
9+
use Drupal\node\Entity\NodeType;
910
use Drupal\Tests\node\Traits\NodeCreationTrait;
1011
use Drupal\Tests\user\Traits\UserCreationTrait;
1112
use Drupal\user\Entity\User;
@@ -52,6 +53,8 @@ protected function setUp(): void {
5253
$this->installConfig(['filter', 'next']);
5354
$this->installSchema('node', ['node_access']);
5455

56+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
57+
5558
$this->nextSettingsManager = $this->container->get('next.settings.manager');
5659

5760
// Create NextSite entities.

modules/next/tests/src/Kernel/Plugin/SiteResolverTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,9 @@ protected function setUp(): void {
3535
$this->installConfig(['filter']);
3636
$this->installSchema('node', ['node_access']);
3737

38-
// Create page type.
39-
$page_type = NodeType::create([
40-
'type' => 'page',
41-
'label' => 'Page',
42-
]);
43-
$page_type->save();
44-
45-
$article_type = NodeType::create([
46-
'type' => 'article',
47-
'label' => 'Article',
48-
]);
49-
$article_type->save();
38+
// Create content types.
39+
NodeType::create(['type' => 'page', 'name' => 'Page'])->save();
40+
NodeType::create(['type' => 'article', 'name' => 'Article'])->save();
5041

5142
// Create NextSite entities.
5243
$blog = NextSite::create([

0 commit comments

Comments
 (0)