API page: https://api.drupal.org/api/drupal/core%21modules%21node%21node.module/fu...

Enter a descriptive title (above) relating to function node_load, then describe the problem you have found:

This page says the following:

Deprecated

in Drupal 8.x, will be removed before Drupal 9.0. Use \Drupal\node\Entity\Node::load().

I understand the desire to Deprecate node_load. The comment points the user to Node::load() as an alternative which is also correct. The problem is Node:load() is not found when the API is searched. This is very frustrating as we are referring a user to a method that seemingly does not exist in the API. The documentation system needs to be a bit more helpful in this case.

Comments

Greg Sims created an issue. See original summary.

cilefen’s picture

Status: Active » Needs review
StatusFileSize
new491 bytes

The reason is that Node::load() does not reimplement Entity::load() so you have to see Entity::load() instead.

Greg Sims’s picture

If I understand the patch correctly, the user will now by pointed to Entity::load(). I understand that this is technically correct as Node::load() is based on Entity::load().

Many users will have used node_load() for years and now need to learn something new. The method they need to use is Node::load() as the originally comment says. If you tell the user to use Entity::load(), this will be confusing and not the optimum solution. The right answer technically is to use Node::load(). Node::load() needs to be documented so the user can find it when they place this in the search bar. I understand Node::load() it is an extension of Entity::load() and so this might be challenging. At the very least, we need an example of how to use Node::load() including arguments and return values. Here are a couple of questions that I had: Can I search for a node with a given Title? What is returned if the entity_id I pass does not exist? These are questions that an API user wants to know.

Please note that the arguments of node_load are not the same as Node::load() -- again this is confusing and difficult to decern from the documentation in the API.

By the way, I am not being picky here. I am explaining a real experience for myself as I come up to speed with Drupal 8. I hope this is helpful to you and others.

cilefen’s picture

I am not offering this as a solution but this change record has some more information on the new API: EntityInterface::load(), loadMultiple() and create() added to load and create new entities.

Another approach to documenting this in the way you feel it should be documented would be to implement the load function in Node, and use the {@inheritdoc} annotation. But I don't know whether we ever do that simply for documentation purposes. The "@see" that I posted in #2 would help on its own.

If you tell the user to use Entity::load(), this will be confusing and not the optimum solution.

Actually, that would work.

jhodgdon’s picture

Status: Needs review » Needs work

Hm. What about saying something like this in the @deprecated documentation:

Use \Drupal\node\Entity\Node::load() (see \Drupal\Core\Entity::load() for documentation).

The problem with using a separate @see is that on api.drupal.org, the @see makes a separate See Also section on the page, which is not necessarily located right where the Deprecated section is. So it won't necessarily be clear to people that they would need to look at the See Also section.

Thoughts?

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new623 bytes

That works for me.

jhodgdon’s picture

Status: Needs review » Needs work

Thanks! Looks good, except:

+++ b/core/modules/node/node.module
@@ -438,7 +438,8 @@ function node_load_multiple(array $nids = NULL, $reset = FALSE) {
+ *   Use \Drupal\node\Entity\Node::load() (see \Drupal\Core\Entity::load() for

That is not the right namespace for Entity::load().

Should be
\Drupal\Core\Entity\Entity::load() I think?

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new589 bytes
new630 bytes

That will teach me to copy and paste.

jhodgdon’s picture

Title: Node:load() Does Not Exist in the API » Node:load() does not exist in the API so link doesn't get made
Status: Needs review » Reviewed & tested by the community

Yeah, time to learn not to copy my suggestions exactly without checking them. ;)

Thanks!

xjm’s picture

Title: Node:load() does not exist in the API so link doesn't get made » Node::load() and similar are inherited from the parent so link doesn't get made on api.d.o
Status: Reviewed & tested by the community » Needs work

Thanks @Greg Sims, good catch! The suggested solution makes sense to me.

There are several other similar deprecations in core that need a similar fix; for example for user_load(). Can we fix those in this patch as well? I checked for them by doing this grep:

grep -r "::load()" * |  grep '*'
Greg Sims’s picture

I searched the API for \Drupal\Core\Entity\Entity::load() and found nothing.

fyi, Greg

cilefen’s picture

"Entity::load" works.

cilefen’s picture

A faster finder: egrep -r "\*.*::load\(\)" *

cilefen’s picture

Issue tags: +Novice

I am tagging this Novice because a novice can follow on with the #8 patch with the information from #10 and #13 to complete the issue.

snehi’s picture

@XJM can we do it with file_load and term_load, role_load with user_load ?

cilefen’s picture

@snehi Go ahead and write a patch.

snehi’s picture

Assigned: Unassigned » snehi
DeanRae’s picture

Assigned: snehi » DeanRae
Issue tags: +CatalystAcademy

Unassigning @Snehi as there has been no activity for three weeks. Picking up on this as a part of catalyst academy. This will be my first ever patch for drupal. Thanks for all the future help :)

DeanRae’s picture

Assigned: DeanRae » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.45 KB
new4.01 KB

We used the following grep command: grep -rn "::load()" * | grep '*' | grep '\.module' to identify the functions to modify and we have adhered to the drupal coding standards which is the 80 character line rule. This is my first patch ever :D

cilefen’s picture

An interdiff on a first-ever patch? That must be some kind of a record.

miteshmap’s picture

Status: Needs review » Reviewed & tested by the community

patch works fine.!

jhodgdon’s picture

Status: Reviewed & tested by the community » Needs work

This actually needs a bit more work before it's ready:

  1. Not everything in node.module or file.module is fixed in this patch. There is also node_type_multiple() and file_load_multiple(). I didn't look elsewhere... but besides the files that have fixes in this patch, there may also be functions that are not in .module files. So I think the grep in #19 didn't catch everything.
  2. +++ b/core/modules/node/node.module
    @@ -240,7 +240,8 @@ function node_mark($nid, $timestamp) {
      * @deprecated in Drupal 8.x, will be removed before Drupal 9.0.
    - *   Use \Drupal\node\Entity\NodeType::loadMultiple().
    + *   Use \Drupal\node\Entity\NodeType::loadMultiple() (see
    + *   \Drupal\Core\Entity\Entity::loadMultiple() for documentation).
      *
      * @see \Drupal\node\Entity\NodeType::load()
    

    We should also fix the @see at the end of this doc block, which (for the same reason) will not work... or maybe just get rid of it. There may be others in Core, which should be caught by a better grep too.

tstoeckler’s picture

We should also fix the @see at the end of this doc block, which (for the same reason) will not work... or maybe just get rid of it. There may be others in Core, which should be caught by a better grep too.

Not necessarily advocating for anything here, just wanted to bring this up: IDEs will highlight @see's like this just fine, so it does provide some value as is (generally speaking not sure about this particular one). That doesn't of course make it less unfortunate that it's not linked on api.drupal.org

DeanRae’s picture

Assigned: Unassigned » DeanRae

Assigned to myself so i can reroll the patch. I have taken into account the new feedback, thanks for the help :)

DeanRae’s picture

Assigned: DeanRae » Unassigned
Status: Needs work » Needs review
StatusFileSize
new8.08 KB
new6.74 KB

As per @jhodgdon suggestion, I have run the following grep: grep -rn "::load()\|:loadMultiple()" * | grep '*' | grep -v 'Test.php' to look for any that I have missed. I fixed those and then also added and removed @see 's to make the documentation more consistent.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! I think this is fine, and I think all the @see changes make perfect sense -- they will link people to where the docs actually are, which is a good thing.

Note: I could gripe about the order of doc blocks -- we have standards for how these things are supposed to be ordered at https://www.drupal.org/node/1354#order -- but it would be out of scope for this issue, and this patch is not really making that worse than it already is. So let's just ship it.

catch’s picture

Status: Reviewed & tested by the community » Needs work

api.drupal.org has the information available that the Node class has a load method - it's listed at https://api.drupal.org/api/drupal/core%21modules%21node%21src%21Entity%2...

So it seems like it should be possible to resolve that when constructing api.drupal.org links as well. That would be an api module patch and might not be straightforward, but I'm not sure working around it with extra references in core helps. Also why not linking to the interface method rather than the parent class?

jhodgdon’s picture

OK.

That's definitely a good point about the interface method. Also filed this issue in the API project:
#2656976: Links to inherited class members are not made

jhodgdon’s picture

Status: Needs work » Closed (won't fix)

I've actually got the API module patch made already (although the fix is not on api.drupal.org yet). So... maybe we should just mark this as Won't Fix?

Greg Sims’s picture

Status: Closed (won't fix) » Needs work

@jhodgdon I'm confused here Jennifer. https://www.drupal.org/node/2656976 is a R7 issue. It seems that we are not addressing the R8 problem with that issue. Would it be OK to leave this issue open until there is a solution for R8 at api.drupal.org?

catch’s picture

Status: Needs work » Closed (won't fix)

@Greg Sims the api module is for 7.x only, but the fix there will work for 8.x on d.o, so this is fine as won't fix for core.

jhodgdon’s picture

@Greg Sims - go to api.drupal.org -- it's fixed there now.

Greg Sims’s picture

Status: Closed (won't fix) » Needs review

@catch I did a search for node::load on api.drupal.org -- the search returns null. I also tried user::load -- it also returns null.

If you folks don't want to fix this for some reason, I'm fine with that. I do want to make sure we are communicating. I am just trying to help the next D8 novice that falls into this same hole.

tstoeckler’s picture

@Greg Sims: If you go to https://api.drupal.org/api/drupal/core!modules!node!node.module/function... now you will see that Node::load() is now a link. It links to Entity::load. The fact that Node::load() is not available in the search autocomplete is a valid point, but I suppose that's another issue (also for API module).

Greg Sims’s picture

Please see the original problem:

The problem is Node:load() is not found when the API is searched. This is very frustrating as we are referring a user to a method that seemingly does not exist in the API. The documentation system needs to be a bit more helpful in this case.

Finding Node::load() in the API search is where we started.

cilefen’s picture

Re #32-35. I think the issue is that it is a head-scratcher to mention Node::load() but link to Entity::load(), even though Entity::load() is technically correct. I think it is fine in terms of the link, but imagine the case where a developer reads the node_load() documentation in the codebase then cannot find anything when searching the API site for Node::load().

Re #34:

To make searching for Node::load() possible, the API site would have to implement full-text search, or, generate a documentation page for every function that was not re-implemented in every level of every inheritance tree.

Greg Sims’s picture

To make searching for Node::load() possible, the API site would have to implement full-text search, or, generate a documentation page for every function that was not re-implemented in every level of every inheritance tree.

I believe every function should have its own page. node_load has a page for every release. Why should node::load be any different? When we are writing code, we need to understand how to load a node into memory -- independent of how the function is implemented.

Inheritance is a very structured part of the PHP language. Would it not be possible to use this structure to create the documentation for each function automatically? Clearly some code is required, but the result could be a huge improvement to the documentation across many functions -- not just node::load().

almaudoh’s picture

Why should node::load be any different?

Except that documentation is done for actual methods in a class. Node::load() is not an actual method.

Would it not be possible to use this structure to create the documentation for each function automatically?

This would mean, a separate documentation page for every method that is inherited from a parent class. We don't normally expect to separately document e.g. Node::getFieldDefinitions(), Node::toArray(), Node::getIterator(), User::getFieldDefinitions(), User::toArray(), User::getIterator(), etc., for all content entities - that's not scalable. Node::load() is just a specific case of this.

To make searching for Node::load() possible, the API site would have to implement full-text search

This sounds like the best solution. I actually thought api.drupal.org had full-text search already...

jhodgdon’s picture

Status: Needs review » Closed (won't fix)

OK.

First of all, the API module does support full-text search. We do not, however, have it turned on for api.drupal.org.

Second, turning on full-text search would not make there be a page on api.drupal.org for Node::load(), and I don't think that the existing page for Entity::load() would appear in full-text search results, because there is no page for Node::load(). At best, a function like node_load(), which has the text "Node::load()" in its documentation, would come up, and then the link would still go to the Entity::load() page.

So. There is not really a Node::load() method. We are not going to make a page for every inherited method. We have a page for the Node class, and you can see all of the inherited methods on it, with their actual names. #38 is correct -- it doesn't scale. So, I'm sorry, but this is as fixed as it will get.

The issue title here is about making *links* -- that was fixed. But making functions that don't exist have pages, and making them appear in the autocomplete, is not going to happen. Full text search could happen -- if you would like to advocate for that, please file an issue in the "api.drupal.org customizations" project if there isn't already one:
https://www.drupal.org/project/apidrupalorg

Back to Won't Fix.

Greg Sims’s picture

@jhodgdon Thanks for evaluating this issue further. It seems that it is just too difficult to go beyond what is in place. With regard to the title of this issue, please see #9 -- the title was changed from the original. Thanks again for all your help! Greg