diff -ruN a/dist/js/more_actions.js b/dist/js/more_actions.js --- a/dist/js/more_actions.js +++ b/dist/js/more_actions.js @@ -14,7 +14,7 @@ }))))); }, updateFormId: function(newParent, form) { - const formActions = form.querySelector('[data-drupal-selector="edit-actions"]'), actionButtons = Array.from(formActions.children); + const formActions = form.querySelector('[data-drupal-selector="edit-actions"]'), actionButtons = Array.from(formActions.querySelectorAll(':scope > input[type="submit"], :scope > .dropbutton-wrapper input[type="submit"], :scope > button[type="submit"], :scope > .dropbutton-wrapper button[type="submit"]')); if (actionButtons.length > 0) { const formId = form.getAttribute("id"); once("ginSyncActionButtons", actionButtons).forEach((el => { diff -ruN a/js/more_actions.js b/js/more_actions.js --- a/js/more_actions.js +++ b/js/more_actions.js @@ -38,7 +38,7 @@ updateFormId: function (newParent, form) { // Attach form elements to main form const formActions = form.querySelector('[data-drupal-selector="edit-actions"]'); - const actionButtons = Array.from(formActions.children); + const actionButtons = Array.from(formActions.querySelectorAll(':scope > input[type="submit"], :scope > .dropbutton-wrapper input[type="submit"], :scope > button[type="submit"], :scope > .dropbutton-wrapper button[type="submit"]')); // Keep buttons in sync. if (actionButtons.length > 0) { diff -ruN a/src/GinContentFormHelper.php b/src/GinContentFormHelper.php --- a/src/GinContentFormHelper.php +++ b/src/GinContentFormHelper.php @@ -270,6 +270,25 @@ $form['gin_sticky_actions']['more_actions']['more_actions_items']['#weight'] = 2; $form['gin_sticky_actions']['more_actions']['more_actions_items']['#attributes']['class'] = ['gin-more-actions__menu']; + // Identify primary buttons from #dropbutton groups. When a form uses + // #dropbutton (e.g. Feeds), the lowest-weight button in each group + // should be the primary visible action in the sticky bar. + $dropbutton_primary_keys = []; + $dropbutton_member_keys = []; + $dropbutton_groups = []; + foreach (Element::children($form['actions']) as $key) { + $btn = $form['actions'][$key] ?? []; + if (($btn['#access'] ?? TRUE) && !empty($btn['#dropbutton'])) { + $group = $btn['#dropbutton']; + $dropbutton_groups[$group][$key] = $btn['#weight'] ?? 0; + $dropbutton_member_keys[$key] = $group; + } + } + foreach ($dropbutton_groups as $group => $buttons) { + asort($buttons); + $dropbutton_primary_keys[array_key_first($buttons)] = TRUE; + } + // Build actions. foreach (Element::children($form['actions']) as $key) { $button = ($form['actions'][$key]) ?? []; @@ -278,6 +297,13 @@ continue; } + // Skip dropbutton wrapper elements created by + // Actions::preRenderActionsDropbutton(). Individual buttons inside + // the dropbutton are also present as direct children of actions. + if (($button['#type'] ?? '') === 'dropbutton') { + continue; + } + if (_gin_module_is_active('navigation')) { $form['gin_sticky_actions']['actions'][$key] = $button; } @@ -285,15 +311,33 @@ // The media_type_add_form form is a special case. // @see https://www.drupal.org/project/gin/issues/3534385 // @see \Drupal\media\MediaTypeForm::actions - if ($button['#type'] ?? '' === 'submit' || $form['#form_id'] === 'media_type_add_form') { + if (($button['#type'] ?? '') === 'submit' || $form['#form_id'] === 'media_type_add_form') { + // Reset rendering flags that may have been set by + // Actions::preRenderActionsDropbutton()'s renderInIsolation(). + unset($button['#printed']); + unset($button['#children']); + unset($button['#markup']); + // Remove #dropbutton to render as individual buttons in the sticky bar. + unset($button['#dropbutton']); + // Update button. $button['#attributes']['id'] = 'gin-sticky-' . $button['#id']; $button['#attributes']['form'] = $form['#id']; $button['#attributes']['data-drupal-selector'] = 'gin-sticky-' . $button['#attributes']['data-drupal-selector']; $button['#attributes']['data-gin-sticky-form-selector'] = $button['#attributes']['data-drupal-selector']; - // Add the button to the form actions array. - if (_gin_module_is_active('navigation') || in_array($key, $includes, TRUE) || !empty($button['#gin_action_item'])) { + // For dropbutton group members, use weight-based ordering: + // lowest weight = primary action, others = more actions. + if (isset($dropbutton_member_keys[$key])) { + if (isset($dropbutton_primary_keys[$key])) { + $form['gin_sticky_actions']['actions'][$key] = $button; + } + else { + $form['gin_sticky_actions']['more_actions']['more_actions_items'][$key] = $button; + } + } + // For non-dropbutton buttons, use existing includes-based logic. + elseif (_gin_module_is_active('navigation') || in_array($key, $includes, TRUE) || !empty($button['#gin_action_item'])) { $form['gin_sticky_actions']['actions'][$key] = $button; } // Add to more menu.