aldaflux/table-triable-bundle
Installation:
composer require aldaflux/table-triable-bundle
Ensure your composer.json meets the PHP (>=5.3.2) and Symfony (>=3.0) requirements.
Enable the Bundle:
Add to config/bundles.php:
return [
// ...
Aldaflux\TableTriableBundle\AldafluxTableTriableBundle::class => ['all' => true],
];
Basic Twig Integration:
Include the CSS/JS in your base template (base.html.twig):
{% stylesheets '@AldafluxTableTriableBundle/Resources/public/css/*' %}
<link href="{{ asset_url }}" rel="stylesheet" />
{% endstylesheets %}
{% javascripts
'@AldafluxTableTriableBundle/Resources/public/js/*'
%}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
First Use Case: Add a triable link to a DataTable row (e.g., in a Twig template):
<a href="{{ path('delete_item', {'id': item.id}) }}"
class="btn btn-danger triable-link"
data-confirm="Are you sure you want to delete this item?"
data-confirm-cancel="Cancel"
data-confirm-ok="Delete">
Delete
</a>
Markup Integration:
Use the triable-link class on anchor tags (<a>) to enable confirmation dialogs. Required attributes:
data-confirm: Confirmation message.data-confirm-ok: Text for the "OK" button (default: "OK").data-confirm-cancel: Text for the "Cancel" button (default: "Cancel").DataTables Compatibility: The bundle includes DataTables JS/CSS. Extend your DataTable initialization:
$('#example').DataTable({
// ... your config ...
});
// Initialize triable links after DataTable loads
$('.triable-link').triable();
Dynamic Confirmation Messages: Use Twig variables for dynamic messages:
<a href="{{ path('archive_item', {'id': item.id}) }}"
class="triable-link"
data-confirm="Archive '{{ item.name }}'? This cannot be undone."
data-confirm-ok="Archive">
Archive
</a>
Symfony Route Integration:
Pair with Symfony routes (e.g., delete_item):
# config/routes.yaml
delete_item:
path: /items/{id}/delete
controller: App\Controller\ItemController::delete
methods: [DELETE]
Custom Templates: Override the default confirmation modal by extending the Twig template:
{% extends '@AldafluxTableTriableBundle/Resources/views/confirmation_modal.html.twig' %}
{% block modal_title %}Custom Title{% endblock %}
JavaScript Dependency:
tableExtension.js loads after DataTables JS. Use {% javascripts %} blocks or <script> tags in order.CSRF Protection:
<a href="{{ path('delete_item', {'id': item.id}) }}?{{ csrf_token() }}"
class="triable-link"
data-confirm="...">
PHP Version Mismatch:
>=5.3.2. Test locally with php -v before deployment.DataTables Version Conflicts:
1.10.19. If your project uses a different version, exclude the bundled JS/CSS and integrate your own:
// Disable auto-initialization
$('.triable-link').triable({ autoInit: false });
// Manually initialize after your DataTable setup
$('.triable-link').triable();
Check Console for Errors:
F12) and look for 404 errors on JS/CSS files. Verify paths in base.html.twig.Verify Initialization:
tableExtension.js runs by checking for the triable function:
console.log(typeof $.fn.triable); // Should log "function"
Override Defaults:
$('.triable-link').triable({
modalClass: 'custom-modal',
onConfirm: function(url) { console.log('Redirecting to:', url); }
});
Custom Confirmation Logic:
triable function in a separate JS file:
$.fn.triable.defaults.onConfirm = function(url) {
if (confirm('Custom logic check?')) {
window.location.href = url;
}
};
Server-Side Validation:
AbstractController to validate actions before processing:
public function delete(Item $item, Request $request): Response
{
if (!$request->isXmlHttpRequest()) {
throw $this->createAccessDeniedException();
}
// Proceed with deletion
}
Localization:
{% trans choice with {'%name%': item.name} %}
Are you sure you want to delete '%name%'?
{% endtrans %}
How can I help you explore Laravel packages today?