Closed (won't fix)
Project:
Drupal core
Version:
8.0.x-dev
Component:
documentation
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
20 Dec 2015 at 17:08 UTC
Updated:
12 Feb 2016 at 00:12 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
cilefen commentedThe reason is that Node::load() does not reimplement Entity::load() so you have to see Entity::load() instead.
Comment #3
Greg Sims commentedIf 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.
Comment #4
cilefen commentedI 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.
Actually, that would work.
Comment #5
jhodgdonHm. 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?
Comment #6
cilefen commentedThat works for me.
Comment #7
jhodgdonThanks! Looks good, except:
That is not the right namespace for Entity::load().
Should be
\Drupal\Core\Entity\Entity::load() I think?
Comment #8
cilefen commentedThat will teach me to copy and paste.
Comment #9
jhodgdonYeah, time to learn not to copy my suggestions exactly without checking them. ;)
Thanks!
Comment #10
xjmThanks @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:
Comment #11
Greg Sims commentedI searched the API for \Drupal\Core\Entity\Entity::load() and found nothing.
fyi, Greg
Comment #12
cilefen commented"Entity::load" works.
Comment #13
cilefen commentedA faster finder:
egrep -r "\*.*::load\(\)" *Comment #14
cilefen commentedI 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.
Comment #15
snehi commented@XJM can we do it with file_load and term_load, role_load with user_load ?
Comment #16
cilefen commented@snehi Go ahead and write a patch.
Comment #17
snehi commentedComment #18
DeanRae commentedUnassigning @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 :)
Comment #19
DeanRae commentedWe 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 :DComment #20
cilefen commentedAn interdiff on a first-ever patch? That must be some kind of a record.
Comment #21
miteshmappatch works fine.!
Comment #22
jhodgdonThis actually needs a bit more work before it's ready:
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.
Comment #23
tstoecklerNot 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
Comment #24
DeanRae commentedAssigned to myself so i can reroll the patch. I have taken into account the new feedback, thanks for the help :)
Comment #25
DeanRae commentedAs 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.Comment #26
jhodgdonThanks! 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.
Comment #27
catchapi.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?
Comment #28
jhodgdonOK.
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
Comment #29
jhodgdonI'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?
Comment #30
Greg Sims commented@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?
Comment #31
catch@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.
Comment #32
jhodgdon@Greg Sims - go to api.drupal.org -- it's fixed there now.
Comment #33
Greg Sims commented@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.
Comment #34
tstoeckler@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).
Comment #35
Greg Sims commentedPlease see the original problem:
Finding Node::load() in the API search is where we started.
Comment #36
cilefen commentedRe #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.
Comment #37
Greg Sims commentedI 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().
Comment #38
almaudoh commentedExcept that documentation is done for actual methods in a class. Node::load() is not an actual method.
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.This sounds like the best solution. I actually thought api.drupal.org had full-text search already...
Comment #39
jhodgdonOK.
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.
Comment #40
Greg Sims commented@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