Skip to content

How do I view a node in Drupal? I get errors if I set up a Next.js entity type #451

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

Closed
skyeinthecloud opened this issue Feb 22, 2023 · 8 comments

Comments

@skyeinthecloud
Copy link

skyeinthecloud commented Feb 22, 2023

I'm just wanting to view a node when I'm logged into my Drupal site as an admin.
If I set up entity types under /admin/config/services/next/entity-types

All I get is errors when visiting the node, e.g https://my-drupal-site.pantheonsite.io/blog/new-article

If Preview mode is configured for the entity type I get an Invalid URI exception, otherwise I get a getSitesForEntity() error.
Also do I even need to configure an entity type if I'm not using Preview mode...?

Config:

  • Drupal 9.5.3
  • Next-drupal 1.6
  • PHP 8.1
The website encountered an unexpected error. Please try again later.

InvalidArgumentException: The URI '' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 293 of core/lib/Drupal/Core/Url.php).
Drupal\next\Plugin\Next\PreviewUrlGenerator\SimpleOauth->generate(Object, Object, 'rel:latest-version') (Line: 222)
Drupal\next\Entity\NextSite->getPreviewUrlForEntity(Object) (Line: 165)
Drupal\next\Plugin\Next\SitePreviewer\Iframe->render(Object, Array) (Line: 129)
Drupal\next\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 68)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
The website encountered an unexpected error. Please try again later.
Error: Call to a member function getSitesForEntity() on null in Drupal\next\Render\MainContent\HtmlRenderer->prepare() (line 115 of modules/composer/next/src/Render/MainContent/HtmlRenderer.php).
Drupal\next\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 68)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 49)
Asm89\Stack\Cors->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 713)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
@shadcn
Copy link
Contributor

shadcn commented Feb 22, 2023

@championlife What does your entity type config looks like?

@skyeinthecloud
Copy link
Author

I'll post a few screencaps, thanks.

Screen Shot 2023-02-23 at 8 44 10 am
Screen Shot 2023-02-23 at 8 44 25 am
Screen Shot 2023-02-23 at 8 44 54 am

@twfahey1
Copy link

twfahey1 commented Feb 23, 2023 via email

@skyeinthecloud
Copy link
Author

@twfahey1 Thanks! It didn't work initially when I created a Pattern and tried to Bulk Generate aliases.
But after manually editing a node -> clicking "Generate path alias" and re-saving it DOES work.

Because I had pre-existing nodes before I created a Pattern, it caused the error as Pathauto didn't Bulk Update those aliases.
Creating new nodes after I created the Pattern - it automatically generates an alias fine.

@TommyBloom
Copy link

Are you able to get revalidate working without preview mode? It errors out for me when preview is not set, I believe its due to not knowing the site revalidate url?

AH01071: Got error 'PHP message: Uncaught PHP Exception Error: "Call to a member function getSitesForEntity() on null" at httpdocs/web/modules/contrib/next/src/Render/MainContent/HtmlRenderer.php line 115

@camilo-escobar
Copy link

camilo-escobar commented May 4, 2023

I have the same question and concern as @TommyBloom: can we use the revalidation feature without enabling preview mode?
It seems that the current answer is 'no'. I needed to choose a Preview Mode plugin ("Site Selector") and check one of my Next.js sites in the entity type configuration to get revalidate working. Without selecting a site, revalidate will not work. I think the site selection setting should not be tied to the "Preview Mode" option. One should be able to select a site and then specify whether to use the preview feature, revalidate, or both.
image

Also, I had to set a "Preview URL" in the Next.js site configuration, in order to prevent the original error reported in this issue:
`InvalidArgumentException: The URI '' is invalid. You must use a valid URI scheme. in Drupal\Core\Url::fromUri() (line 293 of /app/web/core/lib/Drupal/Core/Url.php).
image

All of this forces the use of Preview Mode if you want to take advantage of on-demand revalidation.

@shadcn
Copy link
Contributor

shadcn commented May 4, 2023

One should be able to select a site and then specify whether to use the preview feature, revalidate, or both.

Agree on this. This makes sense.

The reason it works this way right now is revalidation was added in a later release. So we built it on top of the existing preview configuration for compatibility.

@camilo-escobar Would you be interested in creating a separate issue for this? I'm adding this to the roadmap for 2.0

@camilo-escobar
Copy link

@shadcn, thanks for your reply.
A new issue was created: #496

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants