Problem/Motivation

In \Drupal\Core\Render\Element\Actions::preRenderActionsDropbutton has a serious issue where it prematurely renders the buttons in an effort to "clone" them. This causes major issues when certain things are present on the button, like a #ajax or #attached, and effectively get lost because they're not part of the higher render root.

Also, there is @todo Move this to #pre_render in \Drupal\Core\Render\Element\Actions::getInfo which specifically refers to the above method. As it stands now, this method is actually only ever invoked if it's in a form (which in turn is invoked via #process).

Proposed resolution

Simply clone the button in question to the dropbutton render array and then set '#printed' => TRUE on the original element to effectively "hide" it.

Also, move the preRenderActionsDropbutton callback to an actual #pre_render callback.

Remaining tasks

  • Create patch
  • Create test

User interface changes

None

API changes

None

Data model changes

None

Comments

markcarver created an issue. See original summary.

markhalliwell’s picture

Status: Active » Needs review
StatusFileSize
new2.61 KB
markhalliwell’s picture

Issue tags: +Needs backport to 8.3.x, +needs backport to 8.2.x

This patch can be easily backported to prior versions as well.

markhalliwell’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 2: action_dropbuttons_are-2855458-2.patch, failed testing.

markhalliwell’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

Random test failures :-/

Not random, bad function signature since it was moved to an actual #pre_render.

markhalliwell’s picture

StatusFileSize
new4.24 KB
new2.07 KB
markhalliwell’s picture

Title: Action dropbuttons are prematurely rendered on only in #process » Action dropbuttons are prematurely rendered and available only in #process

Title typo

joelpittet’s picture

Thank you for taking this on @markcarver. Just for context the @todo was from this issue #2326891: Convert system_element_info() to Element classes

Any ideas on how you'd like to test it? I'm guessing you found this during trying out #ajax on a drop button?

markhalliwell’s picture

Any ideas on how you'd like to test it?

Idk, Drupal tests aren't really my thing.

I'm guessing you found this during trying out #ajax on a drop button?

Correct. The #ajax property never gets processed because:

  1. It's rendered outside the global render context (renderPlain) and all #attached bubbled metadata is lost
  2. Because of the above, it's rendered outside of a form building process so the "#pre_render" method is never invoked because it's actually defined as a #process callback

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

markhalliwell’s picture

Status: Needs review » Needs work
Issue tags: -Needs backport to 8.3.x, -needs backport to 8.2.x +Needs reroll

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

MerryHamster’s picture

StatusFileSize
new3.88 KB

Reroll patch from #7 for 8.7.x

MerryHamster’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 15: 2855458-15.patch, failed testing. View results

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quiron’s picture

StatusFileSize
new905 bytes
new4.04 KB

With this few changes is passing the tests and working fine.

quiron’s picture

Status: Needs work » Needs review
eli-t’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Render/Element/Actions.php
@@ -67,51 +68,52 @@ public static function processActions(&$element, FormStateInterface $form_state,
+          'title' => $element[$key],

If we no longer refer to $button in this line, $button is never referenced after it is assigned. Therefore we should remove this variable. We can still call renderPlain() if we need the side effects, but there is no point assigning the return value to something we never use.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nikhil_110’s picture

StatusFileSize
new4.78 KB

Attached patch against drupal 10.1.x

sahil.goyal’s picture

StatusFileSize
new6.55 KB
new3.78 KB

Fixing CCF errors #30 update the patch and attaching the interdiff along.

sahil.goyal’s picture

StatusFileSize
new6.56 KB
new3.94 KB

Updating patch again.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.