fix: give collection item macro arguments explicit defaults - #244
Merged
Conversation
Twig 4.0 makes a macro argument required unless it declares a default value. The renderCollectionItem macro is called from project form themes that override collection_widget or collection_rows, so a call passing fewer than three arguments would start raising "Value for argument allow_delete is required for macro renderCollectionItem". Declaring `= false` for both booleans reproduces what the `is defined` guards in the macro body did, so rendered output is unchanged for every existing call. With the defaults in the signature those guards are dead code and are removed. The guard in collection_widget is left alone: it reads a form theme variable, not a macro argument, and can genuinely be undefined. Document the macro signature in docs/forms.md, including that the import belongs inside the block that uses it, since form theme blocks run in the context of the template being rendered. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Contributor
Reviewer's GuideUpdates renderCollectionItem to accept omitted boolean options under Twig 4.0 without changing existing output, and documents the signature and correct usage for custom form theme overrides. Sequence diagram for collection item macro rendering with optional controlssequenceDiagram
participant Theme as Custom form theme
participant Macro as renderCollectionItem
participant Twig as Twig 4.0
participant Output as Rendered row
Theme->>Macro: renderCollectionItem(item, allow_delete, allow_drag_and_drop)
Twig->>Macro: Apply false defaults for omitted booleans
Macro->>Macro: form_widget(item)
Macro->>Macro: form_errors(item)
opt allow_drag_and_drop
Macro->>Output: Render drag handle
end
opt allow_delete
Macro->>Output: Render delete button
end
Macro-->>Theme: Render collection row
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
tijsverkoyen
approved these changes
Sep 7, 2026
jonasdekeukelaere
approved these changes
Sep 7, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Twig 4.0 makes a macro argument required unless it declares a default value. The renderCollectionItem macro is called from project form themes that override collection_widget or collection_rows, so a call passing fewer than three arguments would start raising "Value for argument allow_delete is required for macro renderCollectionItem".
Declaring
= falsefor both booleans reproduces what theis definedguards in the macro body did, so rendered output is unchanged for every existing call. With the defaults in the signature those guards are dead code and are removed.The guard in collection_widget is left alone: it reads a form theme variable, not a macro argument, and can genuinely be undefined.
Document the macro signature in docs/forms.md, including that the import belongs inside the block that uses it, since form theme blocks run in the context of the template being rendered.
Summary by Sourcery
Allow collection item rendering macros to omit optional delete and drag-and-drop controls while documenting their use in custom form themes.
Bug Fixes:
Enhancements:
Documentation: