diff --git a/composer.json b/composer.json index 71475358..4f1230d2 100644 --- a/composer.json +++ b/composer.json @@ -59,6 +59,7 @@ "drupal/mathjax": "^4.0", "drupal/menu_block": "^1.10", "drupal/name": "^1.0@RC", + "drupal/next": ">=1.6", "drupal/paragraphs": "^1.15", "drupal/pathauto": "^1.11", "drupal/pdb": "^1.0", diff --git a/src/EventSubscriber/EntityEventSubscriber.php b/src/EventSubscriber/EntityEventSubscriber.php index 2cb682ae..a53202aa 100644 --- a/src/EventSubscriber/EntityEventSubscriber.php +++ b/src/EventSubscriber/EntityEventSubscriber.php @@ -21,6 +21,7 @@ use Drupal\core_event_dispatcher\Event\Entity\EntityUpdateEvent; use Drupal\field\FieldStorageConfigInterface; use Drupal\menu_link_content\MenuLinkContentInterface; +use Drupal\next\Entity\NextSiteInterface; use Drupal\node\NodeInterface; use Drupal\stanford_profile_helper\StanfordDefaultContentInterface; use Drupal\user\RoleInterface; @@ -160,6 +161,40 @@ protected static function insertNode(NodeInterface $node): void { } } + /** + * When a new Next site is created, create all Next node entity type configs. + * + * @param \Drupal\next\Entity\NextSiteInterface $next_site + * Created next site config. + */ + protected static function insertNextSite(NextSiteInterface $next_site): void { + $next_storage = \Drupal::entityTypeManager() + ->getStorage('next_entity_type_config'); + $node_types = \Drupal::entityTypeManager() + ->getStorage('node_type') + ->loadMultiple(); + + // Create each of the node type bundle configs. + foreach (array_keys($node_types) as $node_bundle) { + + // Make sure one doesn't already exist. + if (!$next_storage->load("node.$node_bundle")) { + $next_storage->create([ + 'id' => "node.$node_bundle", + 'site_resolver' => 'site_selector', + 'revalidator' => 'path', + 'configuration' => [ + 'sites' => [$next_site->id() => $next_site->id()], + ], + 'revalidator_configuration' => [ + 'revalidate_page' => TRUE, + 'additional_paths' => FALSE, + ], + ])->save(); + } + } + } + /** * On node update event listener. * diff --git a/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php b/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php new file mode 100644 index 00000000..9d03dc60 --- /dev/null +++ b/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php @@ -0,0 +1,39 @@ +getPreviewUrl(), [ + 'query' => [ + 'slug' => $entity->toUrl()->toString(), + 'secret' => $next_site->getPreviewSecret(), + ], + ]); + } + + /** + * {@inheritdoc} + */ + public function validate(Request $request) {} + +} diff --git a/tests/src/Kernel/EventSubscriber/EntityEventSubscriberTest.php b/tests/src/Kernel/EventSubscriber/EntityEventSubscriberTest.php index c53a62e4..32f70806 100644 --- a/tests/src/Kernel/EventSubscriber/EntityEventSubscriberTest.php +++ b/tests/src/Kernel/EventSubscriber/EntityEventSubscriberTest.php @@ -7,7 +7,10 @@ use Drupal\field\Entity\FieldConfig; use Drupal\field\Entity\FieldStorageConfig; use Drupal\menu_link_content\Entity\MenuLinkContent; +use Drupal\next\Entity\NextEntityTypeConfig; +use Drupal\next\Entity\NextSite; use Drupal\node\Entity\Node; +use Drupal\node\Entity\NodeType; use Drupal\path_alias\Entity\PathAlias; use Drupal\redirect\Entity\Redirect; use Drupal\Tests\stanford_profile_helper\Kernel\SuProfileHelperKernelTestBase; @@ -167,4 +170,16 @@ public function testConfigPages() { ->get('xmlsitemap_base_url')); } + public function testNextSite() { + $this->assertEmpty(NextEntityTypeConfig::loadMultiple()); + NextSite::create([ + 'label' => 'Blog', + 'id' => 'blog', + 'base_url' => 'https://blog.com', + 'preview_url' => 'https://blog.com/api/preview', + 'preview_secret' => 'one' + ])->save(); + $this->assertNotEmpty(NextEntityTypeConfig::loadMultiple()); + } + } diff --git a/tests/src/Kernel/SuProfileHelperKernelTestBase.php b/tests/src/Kernel/SuProfileHelperKernelTestBase.php index 3dbb2fee..43848e81 100644 --- a/tests/src/Kernel/SuProfileHelperKernelTestBase.php +++ b/tests/src/Kernel/SuProfileHelperKernelTestBase.php @@ -44,6 +44,7 @@ abstract class SuProfileHelperKernelTestBase extends KernelTestBase { 'paragraphs', 'options', 'file', + 'next', ]; /**