+ // Make sure there are no duplicates in orders.
+ if (!validate_plugin_order($formData)) {
+ throw new PluginConfigOrderException();
+ }
+
+ $plugins = array();
+ $newEnabledPlugins = array();
+ foreach ($formData as $key => $data) {
+ if (startsWith($key, 'order')) {
+ continue;
+ }
+
+ // If there is no order, it means a disabled plugin has been enabled.
+ if (isset($formData['order_' . $key])) {
+ $plugins[(int) $formData['order_' . $key]] = $key;
+ }
+ else {
+ $newEnabledPlugins[] = $key;
+ }
+ }
+
+ // New enabled plugins will be added at the end of order.
+ $plugins = array_merge($plugins, $newEnabledPlugins);