Posted by hbfkf on February 3, 2012 at 11:04am
7 followers
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | documentation |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
| Issue tags: | needs backport to D7, Novice |
Issue Summary
API page: http://api.drupal.org/api/drupal/includes--entity.inc/function/EntityFie...
Dear all,
The documentation of 'Return Value' states:
<?php
$result = $query->execute();
$entities = entity_load($my_type, array_keys($result[$my_type]));
?>It seems that this only works when the result is nonempty. Otherwise $result[$my_type] causes an error message Notice: Undefined index: model in .... To fix this, you must explicitly check for empty results, not so elegant, but necessary it seems.
Kaspar
Comments
#1
Thanks for reporting this! I think a novice patch contributor could probably fix this.
It appears that it needs fixing in Drupal 8 first:
http://api.drupal.org/api/drupal/core--modules--entity--entity.query.inc...
I'm not sure why the Drupal 8 and 7 versions of this method don't link to each other... probably because the file name has changed. Anyway, that's a separate issue, which I'll file in the API module.
#2
For anyone interested, here's the issue about the methods not linking to each other:
#1429314: Other versions linking between branches on methods pages seems to be broken
#3
I've added "The entity type will only exist in the outer array if results were found." to the return description and an if statement has been added to the sample code.
I've also adjusted the line wrap on the first line as the text was wrapping too early - I can remove this change if it shouldn't be included.
#4
Looks good, thanks!
#5
Committed to 8.x. Thanks. Moving to 7.x.
#6
D7 version.
#7
Renamed for testing.
#8
This patch is not the same as th D8 patch. It has a typo "In most this cases this...".
#9
I knew there was something else I fixed in the D8 version. This one should be correct.
#10
Change status.
#11
Thanks -- now the patches are the same (except context). :)
#12
Committed to 7.x. My first commit! :)
#13
YAYYY! :D Welcome, Jennifer!!
#14
Automatically closed -- issue fixed for 2 weeks with no activity.