Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
API page: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
The above (and any other flavours in other interfaces?) should say what it returns when nothing is found. From a cursory glance this appears to be an empty array.
https://api.drupal.org/api/drupal/core!includes!entity.inc/function/enti... is affected too.
Comments
Comment #1
jhodgdonAgreed, it looks like it returns an empty array if there aren't any matching entities.
EntityStorageInterface::loadMultiple() should also document that. And it would also probably be good if load() and loadRevision() documented that they return NULL if no matching entity is found.
Comment #2
jhodgdonComment #3
g3r4 CreditAttribution: g3r4 commentedI'll work on these documentation issues
Comment #4
g3r4 CreditAttribution: g3r4 commentedOk, I think I covered what you said before with this patch
Comment #5
jhodgdonLooks good!
Could you also do me a favor and fix a pet peeve: "id" is a psychological term (ego, supergo, id), whereas "ID" means "identifier". So:
should say "... by their IDs". I realize this was in the existing documentation, but it would be great to get fixed!
Also, in @return lines, if they do not already say "@return array", could you add the "array" there for ones that return an array?
And in
The @return line should say "\Drupal\Core\Entity\EntityInterface|null", since NULL can be returned.
And... hmmm...
It looks like we should check on that. I verified that load() does return NULL if no matching entity is found, but... let's see. It looks like it might return an explicit FALSE, or a NULL, or just not return anything, judging by the actual implementations. That is kind of a mess. We should file a separate issue for that, and take this change out of the patch. Sorry about the misdirection!
#2296115: Several entity loadRevision() methods do not obey the interface contract
Comment #6
jhodgdonComment #7
g3r4 CreditAttribution: g3r4 commented@jhodgdon , Thanks for all the clarification ! do not worry at all about the misdirection, I've also updated the documentation patch accordingly with the changes you made in #2296115: Several entity loadRevision() methods do not obey the interface contract.
Hope this is OK now, if I missed something just let me know :)
Comment #8
joachim CreditAttribution: joachim commented> return an explicit FALSE, or a NULL, or just not return anything,
I'm pretty sure that not returning anything is the same as returning NULL, BTW.
Comment #9
jhodgdonRE #8 - you are right about returning NULL:
http://www.php.net/manual/en/functions.returning-values.php
Anyway... That aside, this patch:
The idea on the other issue is that entity revision loading would return NULL if there is no entity found, not FALSE. But anyway we should probably fix all revision-related docs on the other issue and take them out of this patch. I'll make a note there. Please remove revision stuff from this patch though. It will just conflict with the other issue, and be incorrect.
Also, on the loadUnchanged() method, in practice this calls the load() method, so the documentation there is incorrect about returning FALSE (it would return NULL if not found):
Comment #10
g3r4 CreditAttribution: g3r4 commentedGotcha, I've removed the changes to the doc for loadRevision, and corrected the one for loadUnchanged
Comment #11
jhodgdonThis is related to revisions; we should remove from the patch too:
The rest looks good, thanks!
Comment #12
g3r4 CreditAttribution: g3r4 commentedSorry, missed that one :(
Comment #13
jhodgdonLooks good, thanks!
Comment #14
alexpottCommitted f654024 and pushed to 8.x. Thanks!
Reflowed the comments on commit.