Problem/Motivation
node_get_recent() is unused and untested in core. We should deprecate node_get_recent() in Drupal 10 for removal in Drupal 11, and point people to entity query or views as alternatives.
Since this is a straightforward deprecation with no bc layer we don't need any test coverage for it.
Tagging this as a novice task.
Proposed resolution
We need to add @deprecated to the function documentation, and trigger_error() to the function itself, details of the docs/message format can be found in https://www.drupal.org/about/core/policies/core-change-policies/drupal-d... (and/or search for @deprecated in core to see examples).
Remaining tasks
Patch- Change Record
User interface changes
N/a
API changes
CR #3356654: node_get_recent() is deprecated
Data model changes
N/a
Release notes snippet
Issue fork drupal-3356516
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #4
o_timoshchuk CreditAttribution: o_timoshchuk at DevBranch commentednode_get_recent() function noticed as deprecated in drupal:10.1.0 and is removed from drupal:11.0.0.
Comment #5
elberI will revise it.
Comment #6
elberI 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.
Comment #7
longwaveThis 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.
Comment #8
elberHi please can you give example about it?
Comment #9
longwaveSee https://www.drupal.org/node/3348138 as an example.
Comment #10
elberHi please can you check it https://www.drupal.org/node/3356654
Comment #11
DanielVezaThe 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.Comment #12
jwilson3On Drupal 10.0, executing
node_get_recent(1);
anywhere in your codebase returns a fatal error:This is due to CR #3201242: Access checking must be explicitly specified on content entity queries, which is now enforced in Drupal 10 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:I thought about opening a bug report, 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 in Drupal core would technically be a one-liner and might still make sense to open an issue.
But anyone looking for a quickfix replacement for their own code, would likely look something like this (in a bare-bones case). YMMV.
What do you think? should I open a separate bug report anyway?
Comment #13
jwilson3Is 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.
Comment #14
longwave@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.Comment #15
jwilson3All 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.
Comment #16
jwilson3👆 That being said, I've opened an issue. 😀
#3357368: EntityQuery Access Check in node_get_recent()
Let's see what happens.
Comment #17
catchThat might already have been fixed in #3357368: EntityQuery Access Check in node_get_recent() (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).
Comment #18
DanielVezaUpdated 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.
Comment #19
sharayurajput CreditAttribution: sharayurajput at QED42 for Drupal India Association commentedI will review this issue
Comment #20
jwilson3Added CR to issue summary and filled out what I could of the standard issue summary template.
Comment #21
smustgrave CreditAttribution: smustgrave at Mobomo commentedCR 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.
Comment #22
jwilson3I've taken a stab at adding Release Notes Snippet to the IS. Please have a look.
Comment #23
jwilson3Re #18:
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.
I've added two more examples to the CR:
https://www.drupal.org/node/3356654
Please review
Comment #24
jwilson3Issue summary states:
We have not explicitly pointed people to entity query (link?) or mentioned views as alternatives on the CR.
Comment #27
catchThe 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
Comment #28
andypostSadly this line still mentioning 10.1 https://git.drupalcode.org/project/drupal/-/commit/b455418579d615cfbf4ed...