diff --git a/src/EventSubscriber/EntityEventSubscriber.php b/src/EventSubscriber/EntityEventSubscriber.php index 2cb682ae..4ce5d5d5 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,37 @@ 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(); + + foreach (array_keys($node_types) as $node_bundle) { + 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..becbc0b5 --- /dev/null +++ b/src/Plugin/Next/PreviewUrlGenerator/SimplePreview.php @@ -0,0 +1,40 @@ +toUrl()->toString(); + $query['secret'] = $next_site->getPreviewSecret(); + + return Url::fromUri($next_site->getPreviewUrl(), [ + 'query' => $query, + ]); + } + + /** + * {@inheritdoc} + */ + public function validate(Request $request) {} + +}