Callback Symfony Twig Extension Bundle
TangoMan Callback Twig Extension Bundle provides simple callback function for twig which avoids unnecessary callbacks to stack up indefinitely in users query string., (*2)
Callback
ClassThis class defines a Twig extension that introduces a custom function called callback
. Its main job is to generate clean URLs by removing callback
parameters from query strings, which can help avoid issues where multiple callbacks get appended indefinitely and make sure users query parameters are not lost in the process., (*3)
callbackFunction()
public function callbackFunction($route = null, $parameters = [])
callback
parameter from the query string.Imagine you're building a redirect system where callbacks are passed through URLs. If multiple redirects occur (e.g., login flow, third-party auth, or form submissions), you might get URLs like this:, (*4)
https://example.com/page?callback=https://another.com?callback=...
This class avoids that endless loop by stripping the callback
query parameter from the final URL so it stays nice and tidy., (*5)
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:, (*6)
composer require tangoman/callback-bundle
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation., (*7)
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:, (*8)
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { // ... public function registerBundles() { $bundles = array( // ... new TangoMan\CallbackBundle\TangoManCallbackBundle(), ); // ... } }
You don't have to add TangoMan Callback Twig Extension Bundle to the service.yml
of your project.
twig.extension.callback service will load automatically., (*9)
callback(route = null, parameters = [])
Returns current URI removing callback
from query string.
Optionally, returns the absolute URL (with scheme and host) for the given route with given parameters, callback
will be ignored as well., (*10)
route (optional) | parameters (optional) | |
---|---|---|
type | string | array |
default | current uri | [] |
Inside your views:, (*11)
By default callback will be defined on user's current page., (*12)
<a href="{{ path('app_foo_bar', { 'callback': callback() }) }}"> Your Foo Bar link here </a>
But you can optionally redirect user to any route., (*13)
<a href="{{ path('app_delete_foo', { 'callback': callback('app_trash_bin', { 'slug': 'foo' } ) }) }}"> Your Foo Bar link here </a>
Callback function accepts route name and parameters for desired route., (*14)
Inside your action method:, (*15)
public function foobarAction(Request $request) { ... // User is redirected to referrer page return $this->redirect($request->get('callback')); ... }
TangoMan Callback Twig Extension Bundle provides Makefile script to perform unit tests, in order to fit in your continuous integration workflow., (*16)
Enter following command to install required dependencies and execute unit tests:, (*17)
$ make tests
On windows machine you will need to install cygwin or GnuWin make first to execute make script., (*18)
If you have XDebug installed, you can generate code coverage report with:, (*19)
$ make coverage
If you find any bug please report here : Issues, (*20)
Thank you for your interest in contributing to TangoMan Callback Twig Extension Bundle., (*21)
Please review the code of conduct and contribution guidelines before starting to work on any features., (*22)
If you want to open an issue, please check first if it was not reported already before creating a new one., (*23)
Copyrights (c) 2025 "Matthias Morin" <mat@tangoman.io>, (*24)
Distributed under the MIT license., (*25)
If you like TangoMan Callback Twig Extension Bundle please star, follow or tweet:, (*26)
... And check my other cool projects., (*28)
Looking for an experienced Full-Stack Partner ?, (*29)
Clean code. Clear communication., (*30)
From first sketch to final launch, I've got your back., (*31)