Just trying to work out how the heck to use this module. I found this documented in a comment for entity_dependency_iterator():

<?php

/**
 * Factory function for an entity dependency iterator.
 *
 * The $entities array should be structured as below, where all string keys
 * are entity types and the numeric keys are entity ids.
 * @code
 *   $entities = array(
 *     'node' => array(10, 12),
 *     'taxonomy_term' => array(16),
 *   );
 * @endcode
 */

?>

So you would assume something like this would work:

<?php
$iterator = entity_dependency_iterator(array('node' => array($node->nid)));
?>

But no, that gives errors.

I had a squiz through the code and figured something like this would work:

<?php
$iterator = entity_dependency_iterator(array(array('type' => 'node', 'id' => $node->nid)));
?>

So I think the documentation is a bit misleading there.

Additionally, I also struggled to figure out what to do with the object that was returned, as I was unable to debug it. I had to research what an Iterator class was and found some code to debug the result like so:

<?php
for ($iterator->rewind(); $iterator->valid(); $iterator->next()) {
    try {
        $value = $iterator->current();
    } catch (Exception $exception) {
        continue;
    }
    dpm($value);
}
?>

Seems a bit over the top to me, is there an easier way? (other than removing the try/catch)

Comments

danielb’s picture

Component: Code » Documentation
danielb’s picture

Status: Active » Needs review
StatusFileSize
new1.18 KB

Proposed change.

danielb’s picture

Issue summary: View changes

dfs

rosk0’s picture

It's really frustrating that such simple and good patches doesn't get required attention for years... :(

harshil.maradiya’s picture

Status: Needs review » Reviewed & tested by the community

this patch provides good explanations about iterators