The "insert" part of this request is basically the respective issue as https://www.drupal.org/project/drupal/issues/66183
One of the most difficult things about manipulating Drupal forms is the process of manipulating the arrays themselves. And one of the things that I commonly want to do is "stick this stuff in after that". But I have yet to find a PHP function to manipulate arrays in this way.
So I wrote this function called
array_insert()
. Perhaps there's a cleaner way to handle this, but it seems like a function that should be available in Drupal core. It would certainly help with a lot of commonhook_form_alter()
tasks....
The "move" is something new (no equivalent d.org issue that I could find). I would like to be able to move an existing key in the array from its current position to the start/end of the array. So two new functions, like
backdrop_array_move_key_to_start($array, $key)
/backdrop_array_move_key_to_end($array, $key)
I usually achieve the "move to start" with this:
$my_array = array_merge(array($key => $my_array[$key]), $my_array);
...and "move to end" with this:
$move = $my_array[$key]; unset($my_array[$key]); $my_array[] = $move;
There could be more efficient/performant/readable ways, but it would be a much better DX if we did not have to search the web or previous code in Backdrop to find how to best do it. Helper functions with obvious names would be ideal for all that.
Recent comments
Graham Leach: Has anyone got any experience with the assets in this area of Backdrop CMS? filetransfer.inc ftp.inc local.inc ssh.inc If you do, I'd love to chat with you... Graham...
Jan 16th 2025 Weekly Meetings
I've been building Backdrop sites since 2021 with the first being my own: https://www.systemhorizons.co.uk/ Two over time for one client: https://www....
Happy Birthday Backdrop CMS - Share your projects!
Hi Tim. Yes I think at the moment it needs custom code. Depending where you want the class it could be either: /** * Implements hook_preprocess_page(). */ function theme_name_preprocess_page...
How to make clear to editor if they are on a revision?