Skip to content

Add Blueprint/formPrint compatibility to BootstrapRenderer#111

Draft
f3l1x wants to merge 2 commits intomasterfrom
claude/implement-issue-63-tests-rYXMM
Draft

Add Blueprint/formPrint compatibility to BootstrapRenderer#111
f3l1x wants to merge 2 commits intomasterfrom
claude/implement-issue-63-tests-rYXMM

Conversation

@f3l1x
Copy link
Copy Markdown
Member

@f3l1x f3l1x commented Mar 29, 2026

Summary

This PR adds compatibility with Nette's Blueprint::latte() functionality and the {formPrint} macro by making BootstrapRenderer work with regular Form instances, not just BootstrapForm.

Key Changes

  • Type flexibility: Changed attachForm() parameter type from BootstrapForm to Form to accept any form instance
  • String handling: Added support for string returns from getControl() and getLabel() methods, which Blueprint uses instead of Html objects
  • Validation safety: Introduced isShowValidation() helper method that safely checks if the form is a BootstrapForm before accessing validation properties, returning false for regular forms
  • Return type updates: Updated renderLabel() return type to Html|string to accommodate Blueprint's string-based rendering
  • Cloning support: Ensured the renderer can be cloned and attached to different form instances without errors

Implementation Details

  • The renderer now gracefully handles both Html objects and string returns from control methods
  • Validation styling is only applied when the form is actually a BootstrapForm instance, preventing errors when used with regular forms
  • All changes maintain backward compatibility with existing BootstrapForm usage
  • Added comprehensive test suite (BlueprintCompatibilityTest) covering various scenarios including different render modes, Bootstrap versions, and form types

Testing

Added 13 new tests verifying:

  • Blueprint Latte generation with BootstrapForm
  • Compatibility across all render modes (vertical, side-by-side, inline)
  • Bootstrap 5 support
  • Various input types and form groups
  • Renderer cloning and attachment to regular forms
  • Validation behavior with non-BootstrapForm instances

https://claude.ai/code/session_017S8dLXAbfF5iXKzYq8ADt2

This change enables the {formPrint} Latte macro to work with BootstrapForm.
Previously, using {formPrint} with BootstrapForm would fail because:

1. BootstrapRenderer::attachForm() only accepted BootstrapForm
2. The renderer directly accessed $this->form->showValidation which
   doesn't exist on regular Form objects
3. renderControl() and renderLabel() didn't handle string returns from
   getControl()/getLabel() which Blueprint's dummy controls return

Changes:
- Updated attachForm() to accept Form instead of BootstrapForm
- Added isShowValidation() helper method that safely checks the property
- Updated renderControl() to handle string returns for Blueprint compatibility
- Updated renderLabel() to handle string returns for Blueprint compatibility
- Added comprehensive test suite for Blueprint/formPrint functionality

Fixes: #63
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.

2 participants