computerminds/cm_tools — pull request #2 by jamsilver (2012-02-29 11:10:37+00:00)
Title: Array insert & theme_hook_suggestion helper functions

Some functions which allow one to insert new entries into exact places in arrays. Some use cases:

1. cm_tools_array_insert_at_key() - Altering a form which has lots of elements all of #weight 0 and you need your element(s) to appear in a specific place.

2. cm_tools_array_insert_at_value() - Inserting theme_hook_suggestions. A helper function is included for this with a couple of extra features likely to be useful in this context, but the work is done by cm_tools_array_insert_at_value().

3. cm_tools_array_insert_at_offset() - Turns out to be the best way of consistently implementing insert_at_value() & insert_at_key() to support both numerically- & string-indexed arrays.

4. cm_tools_array_rename_key() - Included to demonstrate how trivial it is to implement using these helpers. Tumti-tumm, I suppose use cases might be... Altering the #links entry on a #theme => 'links' render array to modify the class of a certain link (which is defined by the key), without changing the order of the links.