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)
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity_dependency_iterator_documentation-1589794-1.patch | 1.18 KB | danielb |
Comments
Comment #1
danielb commentedComment #2
danielb commentedProposed change.
Comment #2.0
danielb commenteddfs
Comment #3
rosk0It's really frustrating that such simple and good patches doesn't get required attention for years... :(
Comment #4
harshil.maradiya commentedthis patch provides good explanations about iterators