This may be useful in other places also, but I'll start small with a patch to
links_load_link_for_node()
to allow the caller to define the key used for the returned array. A bit like taxonomy (and others) do these days. The change ($indexedby parameter) looks like:
function links_load_links_for_node($nid, $module='links', $lid=0, $firstonly=FALSE, $indexedby = 'url') {
...
$links[$row[$indexedby]] = $row;
...
return $links;
}
So instead of a count-indexed array being returned, I get something that's a bit easier to check for existing urls in etc. Set it to NULL and you'll get the old behaviour.
It's a trivial change (so far) but I think it's a clean improvement, and better than sorting it later.
Anyone can suggest a different 'default' key to index on if you'd care.
In the meantime, I'm tonight lookng at making the links_related.module actually work (again?) and fix up that edit interface... more suggestions to come.
| Comment | File | Size | Author |
|---|---|---|---|
| links_indexedby.patch | 1.35 KB | dman |
Comments
Comment #1
dman commentedI see this would help clean up the code here
as well...
... actually I see that because it's using a manual for loop instead of a natural foreach something might break a little. ah well. Fixing it will be better.
Comment #2
dman commentedThis can be closed as it's being rolled into a larger update
I encountered a few problems with code elsewhere expecting number-indexed results (always retrieving $links[0] instead of using, eg, array_pop($links) ) so I've set the default behaviour to be the same as legacy, but this feature can be taken advantage of in a few places.