Skip to content

Add a regression test for #pre_render callbacks on a union of classes - #1094

Merged
mglaman merged 1 commit into
mainfrom
bug-457-union-class-callback
Nov 10, 2026
Merged

mglaman merged 1 commit into
mainfrom
bug-457-union-class-callback

Conversation

@mglaman

@mglaman mglaman commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Fixes #457.

The issue reported RenderCallbackRule flagging a callback whose class is picked at runtime:

[$class, $type] = $element['#multiple'] ? [Checkboxes::class, 'checkboxes'] : [Radios::class, 'radios'];
$element['#pre_render'] = [[$class, 'preRenderCompositeFormElement']];
#pre_render callback array{'Drupal\\Core\\Render\\Element\\Checkboxes'|'Drupal\\Core\\Render\\Element\\Radios', 'preRenderCompositeF…'} at key '0' is not callable.

This no longer happens on main. $class is still '…\Checkboxes'|'…\Radios', but the callable check now passes when the method exists on every class in the union. preRenderCompositeFormElement() comes from CompositeFormElementTrait, which both classes use.

This adds the test case the issue asked for, so it stays fixed:

  • [$class, $type] = ... ? [...] : [...] with the method on both classes: not reported.
  • $class = ... ? Checkboxes::class : Radios::class with the method on both classes: not reported.
  • The same union with processCheckboxes(), which only Checkboxes has: reported as not callable, because the Radios case would fail.

No code changes. RenderCallbackRuleTest passes.

🤖 Generated with Claude Code

[$class, 'method'] where $class is Checkboxes::class|Radios::class is
callable when every class has the method, and not callable when only
one does. Both already work on main.

Fixes #457.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mglaman
mglaman merged commit 81de573 into main Nov 10, 2026
19 of 20 checks passed
@mglaman
mglaman deleted the bug-457-union-class-callback branch November 10, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to detect #pre_render callback with dynamic class

1 participant