aldaflux/confirmation-window-bundle
Installation
composer require aldaflux/confirmation-window-bundle
Enable the bundle in config/bundles.php:
Aldaflux\ConfirmationWindowBundle\AldafluxConfirmationWindowBundle::class => ['all' => true],
Basic Configuration
Update aldaflux_confirmation_window.yaml (Symfony) or aldaflux_confirmation_window.php (Laravel port equivalent) with a template (e.g., bootstrap4):
aldaflux_confirmation_window:
template: bootstrap4
delete: true # Enable for delete actions
First Use Case Add a confirmation trigger to a link in Twig:
<a href="{{ path('delete_item', {'id': item.id}) }}" class="delete-link">Delete</a>
Ensure the link has a class matching your config (e.g., delete for delete: true).
Link-Based Triggers
delete, customs.*) to auto-attach confirmation windows.<a href="{{ path('publish_post') }}" class="modif">Publish</a>
Configure in customs.modify with a title and selector.Dynamic Titles/Buttons Override titles/buttons via JavaScript or Twig:
<script>
document.addEventListener('confirmationInit', function(e) {
if (e.detail.selector === '.modif') {
e.detail.title = "Are you sure?";
}
});
</script>
Alerts for Non-Destructive Actions
Use the alerts section for non-link confirmations (e.g., form submissions):
alerts:
alert:
selector: ".submit-form"
title: "Confirm submission?"
Trigger via JavaScript:
document.querySelector('.submit-form').addEventListener('click', () => {
window.confirmationWindow.show('.submit-form');
});
Laravel Blade Adaptation
@confirmationLink).@confirmationLink('delete_item', ['id' => $item->id], 'Delete', 'delete')
Selector Specificity
.modif vs .modif2) may cause unintended triggers. Use unique classes or IDs.Template Mismatches
bootstrap4 template assumes Bootstrap CSS. For custom templates, ensure the JS matches the HTML structure.Event Conflicts
delete: true, ensure no other JS handlers interfere with the confirmation dialog’s preventDefault().Symfony vs. Laravel Porting
resources/views/vendor/aldaflux/confirmation-window.blade.php.aldaflux_confirmation_window.php config file in config/aldaflux.php.Check Console Logs
Look for errors like Uncaught ReferenceError: confirmationWindow is not defined (missing JS load).
Verify Selectors
Use browser dev tools to confirm selectors (e.g., .delete-link) match the config.
Fallback for Missing JS Add a no-JS fallback in Twig/Blade:
{% if app.request.isXmlHttpRequest %}
<a href="{{ path('delete_item') }}" class="delete-link no-js-fallback">Delete</a>
{% else %}
<form method="post" action="{{ path('delete_item') }}">
{{ csrf_field() }}
<button type="submit" class="delete-link">Delete</button>
</form>
{% endif %}
Custom Templates
Extend the default template by copying vendor/aldaflux/confirmation-window-bundle/Resources/views/confirmation_window.html.twig to your theme and overriding it.
Dynamic Configuration Load config via PHP for runtime changes:
# config/aldaflux.php
'customs' => [
'modify' => [
'title' => env('CONFIRM_MODIFY_TITLE', 'Default Title'),
],
],
Event Listeners
Hook into the confirmation.window.init event (if the bundle emits it) to modify behavior dynamically:
document.addEventListener('confirmation.window.init', (e) => {
e.detail.options.class = 'custom-class';
});
How can I help you explore Laravel packages today?