- Issue created by @catch
- 🇺🇦Ukraine o_timoshchuk
o_tymoshchuk → made their first commit to this issue’s fork.
- last update
over 1 year ago 29,343 pass - @o_tymoshchuk opened merge request.
- Status changed to Needs review
over 1 year ago 10:48am 26 April 2023 - 🇺🇦Ukraine o_timoshchuk
node_get_recent() function noticed as deprecated in drupal:10.1.0 and is removed from drupal:11.0.0.
- last update
over 1 year ago 29,343 pass - 🇧🇷Brazil elber Brazil
I just rebased, about the deprecate method I also revised it .
Deprecation document is acording with drupal standards see: https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... →
Waiting someone to review the rebase and this issue as well.
- Status changed to Needs work
over 1 year ago 1:58pm 26 April 2023 - 🇬🇧United Kingdom longwave UK
This needs a change record with an example of a call to node_get_recent() and the replacement query. The deprecation notice should then link to the change record instead of this issue.
- 🇬🇧United Kingdom longwave UK
See https://www.drupal.org/node/3348138 → as an example.
- 🇧🇷Brazil elber Brazil
Hi please can you check it https://www.drupal.org/node/3356654 →
- 🇳🇿New Zealand danielveza Brisbane, AU
The CR could use a bit of background about why this was deprecated. The first line in the issue statement is a good start.
The example also needs to be fleshed out, in particular the after section. The replacement isn't
\Drupal::entityQuery('node')
, it's using EntityQuery to find the most recently changed nodes that the user can access. - 🇪🇨Ecuador jwilson3
On Drupal 10.0, executing
node_get_recent(1);
anywhere in your codebase returns a fatal error:The website encountered an unexpected error. Please try again later. Drupal\Core\Entity\Query\QueryException: Entity queries must explicitly set whether the query should be access checked or not. See Drupal\Core\Entity\Query\QueryInterface::accessCheck(). in Drupal\Core\Entity\Query\Sql\Query->prepare() (line 141 of core/lib/Drupal/Core/Entity/Query/Sql/Query.php). Drupal\Core\Entity\Query\Sql\Query->execute() (Line: 713) node_get_recent(1)
This is due to CR #3201242: Access checking must be explicitly specified on content entity queries → , which is now enforced by throwing an exception if
::accessCheck()
is not explicitly included in any content entity queries. To be honest, this is no surprise because this issue explains the situation succinctly:node_get_recent() is unused and untested in core.
I thought about opening a bug ticket, but then found this issue. As this function is slated to be deprecated in 10.1.0 (this issue) and removed in D11, the pragmatic approach is to just hit the WSOD error like I did; then, stumble across this issue (by searching for the error message I included above) and fixing your code to go ahead and replace the function call with your own entity query.
The fix would technically be a one-liner and might still make sense to open an issue.
function node_get_recent($number = 10) { $account = \Drupal::currentUser(); $query = \Drupal::entityQuery('node'); + $query->accessCheck(TRUE); if (!$account->hasPermission('bypass node access')) { // If the user is able to view their own unpublished nodes, allow them // to see these in addition to published nodes. Check that they actually
But anyone looking for a quickfix replacement for their own code, would likely look something like this (in a bare-bones case). YMMV.
+use Drupal\node\NodeInterface;-$last_updated_node_array = node_get_recent(1);
+$last_updated_node_array = \Drupal::entityQuery('node')
+ ->accessCheck(FALSE)
+ ->condition('status', NodeInterface::PUBLISHED)
+ ->sort('changed', 'DESC')
+ ->range(0, 1)
+ ->addTag('node_access')
+ ->execute();
What do you think? should I open a bug ticket anyway?
- 🇪🇨Ecuador jwilson3
Is the "After" example in this issue's CR correct?
https://www.drupal.org/node/3356654 →
It seems like it is missing several things, like what I outlined in the second diff in comment #12 above.
- 🇬🇧United Kingdom longwave UK
@jwilson3 as noted in #11 the change record is incomplete and needs work.
I am sort of tempted to leave
node_get_recent()
broken, given that it is untested and we are removing it anyway - otherwise we need to add a test to prove that the fix works. But if you want to open a separate bug report, we can look at fixing the access check so it works until it is removed in Drupal 11. - 🇪🇨Ecuador jwilson3
But if you want to open a separate bug report, we can look at fixing the access check so it works until it is removed in Drupal 11.
All it takes is a core committer to block getting the fix in because it doesn't have tests and we're basically back at this issue.
- 🇪🇨Ecuador jwilson3
👆 That being said, I've opened an issue. 😀
🐛 EntityQuery Access Check in node_get_recent() Closed: duplicate
Let's see what happens.
- 🇬🇧United Kingdom catch
That might already have been fixed in 🐛 EntityQuery Access Check in node_get_recent() Closed: duplicate (which is what prompted me to open this issue, since I had no idea node_get_recent() still existed until I saw it again there).
- Status changed to Needs review
over 1 year ago 10:54pm 1 May 2023 - 🇳🇿New Zealand danielveza Brisbane, AU
Updated the CR. I added the example from #12 since I think thats a pretty clean example. However it's not exactly a 1-1 replacement since node_get_recent does some extra checking around if a user can see unpublished nodes etc. Do we want to add that in?
The CR is also currently published.. That feels incorrect to me since this hasn't gone in yet. I didn't want to unpublish it just in case it is meant to be published, so thought I'd flag it.
- Assigned to sharayurajput
- 🇪🇨Ecuador jwilson3
Added CR to issue summary and filled out what I could of the standard issue summary template.
- Status changed to RTBC
over 1 year ago 2:04pm 3 May 2023 - 🇺🇸United States smustgrave
CR looks good.
Deprecation looks simple enough.
Assuming since it's a task that no test deprecation will be needed.
Confirmed node_get_recent is not used in the repo.Looks good.
- last update
over 1 year ago 29,374 pass - 🇪🇨Ecuador jwilson3
I've taken a stab at adding Release Notes Snippet to the IS. Please have a look.
- 🇪🇨Ecuador jwilson3
Re #18:
it's not exactly a 1-1 replacement since node_get_recent does some extra checking around if a user can see unpublished nodes etc. Do we want to add that in?
I think it makes sense to have a simple option and a more advanced option that copies/pastes the functionality more or less verbatim from Drupal 10.1 with all the extra permissions and unpublished and own node logic.
- 🇪🇨Ecuador jwilson3
Issue summary states:
point people to entity query or views as alternatives.
We have not explicitly pointed people to entity query (link?) or mentioned views as alternatives on the CR.
- last update
over 1 year ago 29,378 pass - last update
over 1 year ago 29,379 pass - last update
over 1 year ago 29,380 pass - last update
over 1 year ago 29,383 pass - last update
over 1 year ago 29,388 pass - last update
over 1 year ago 29,387 pass, 2 fail - last update
over 1 year ago 29,380 pass, 3 fail - last update
over 1 year ago 29,388 pass - last update
over 1 year ago 29,387 pass, 2 fail - last update
over 1 year ago 29,388 pass - last update
over 1 year ago 29,395 pass - last update
over 1 year ago 29,399 pass 21:37 18:05 Running- last update
over 1 year ago 29,400 pass - last update
over 1 year ago 29,409 pass - Open on Drupal.org →Environment: PHP 8.1 & MySQL 5.7last update
over 1 year ago Waiting for branch to pass - last update
over 1 year ago 29,418 pass - Status changed to Fixed
over 1 year ago 11:21am 8 June 2023 - 🇬🇧United Kingdom catch
The CR covers this fine now - mentions views at the top and shows explicit entity query alternatives.
We don't need a release note for this one, just the CR is fine.
Committed/pushed to 11.x, thanks! Note per the new core branching scheme this means it'll be in 10.2.x. I updated the deprecation version on commit from 10.1 to 10.2
- 🇫🇷France andypost
Sadly this line still mentioning 10.1 https://git.drupalcode.org/project/drupal/-/commit/b455418579d615cfbf4ed...
Automatically closed - issue fixed for 2 weeks with no activity.