Created
July 14, 2020 14:17
-
-
Save MatthieuScarset/6e5dd50024e4bf7d6295e4555a164ad4 to your computer and use it in GitHub Desktop.
Drupal - Order array by another array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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