Skip to content

Instantly share code, notes, and snippets.

@MatthieuScarset
Created July 14, 2020 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MatthieuScarset/6e5dd50024e4bf7d6295e4555a164ad4 to your computer and use it in GitHub Desktop.
Save MatthieuScarset/6e5dd50024e4bf7d6295e4555a164ad4 to your computer and use it in GitHub Desktop.
Drupal - Order array by another array
<?php
// Reorder actions.
$order = [
'previous',
'reset',
'submit',
'preview_next',
];
$actions = $form['actions'];
uksort($actions, function ($key1, $key2) use ($order) {
return (array_search($key1, $order) > array_search($key2, $order));
});
$i = 0;
foreach (Element::children($actions) as $key) {
$actions[$key]['#weight'] = $i++;
}
$form['actions'] = $actions;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment