addiks/shtumi-useful-bundle
Symfony bundle with handy utilities: AJAX autocomplete, dependent filtered entity, and date range form types, plus extra Doctrine DQL functions (IF, IFNULL, ROUND, DATE_DIFF). Can integrate autocomplete as a SonataAdmin filter.
Installation
Add the bundle to your composer.json (preferred over deps for modern Laravel/Symfony projects):
composer require addiks/shtumi-useful-bundle
Register in config/bundles.php (Symfony) or manually in Laravel via service provider (if adapted).
First Use Case: Ajax Autocomplete
// In a Symfony FormBuilder
$builder->add('user', AjaxAutocompleteType::class, [
'entity' => User::class,
'property' => 'email',
'route' => 'app_user_autocomplete',
]);
collective/html) or wrap in a Laravel-specific trait.DQL Functions
Enable in Doctrine via config/packages/doctrine.yaml:
dql:
string_functions:
IF: Shtumi\UsefulBundle\Doctrine\DQL\IF
IFNULL: Shtumi\UsefulBundle\Doctrine\DQL\IFNULL
Ajax Autocomplete
app_user_autocomplete) returning JSON:
// Symfony Controller
public function autocomplete(Request $request)
{
return $this->get('shtumi_useful.ajax_autocomplete')->getResults(
User::class,
$request->query->get('q'),
'email'
);
}
{{ form_widget(form.user, {'attr': {'data-autocomplete-url': path('app_user_autocomplete')}}) }}
FormBuilder with Laravel’s Form facade or a custom wrapper.Dependent Filtered Entity
$builder->add('country', EntityType::class, ['class' => Country::class])
->add('region', DependentFilteredEntityType::class, [
'entity' => Region::class,
'property' => 'name',
'dependent_property' => 'country',
'dependent_entity' => Country::class,
]);
collective/html or a custom form component.Date Range
$builder->add('dateRange', DateRangeType::class, [
'widget' => 'single_text', // or 'split'
'format' => 'yyyy-MM-dd',
]);
$form->getData() as a DateRange object.$query = $entityManager->createQuery(
'SELECT u FROM App\Entity\User u WHERE IF(u.isActive = 1, u.name, "Inactive") = :name'
);
$query->setParameter('name', 'John');
Model::query() or adapt via a custom query builder trait.Symfony-Specific Assumptions
FormBuilder. Laravel users must:
AbstractType or wrap in a Laravel-specific form builder.path() → route()).// Laravel Form Component (Blade)
<input type="text" data-autocomplete-url="{{ route('user.autocomplete') }}">
DQL Function Registration
Unknown DQL function 'IF'.Shtumi\UsefulBundle\Doctrine\DQL classes are autoloaded and registered in Doctrine’s string_functions.Ajax Autocomplete Performance
Redis or Symfony Cache).Dependent Filtered Entity
required: false and handle empty states in JS:
$('#form_country').change(function() {
if (!this.value) $('#form_region').empty();
});
Form Type Errors
Kernel.php (Symfony) or AppServiceProvider (Laravel).App\Entity\User).DQL Errors
$query = $entityManager->createNativeQuery('SELECT IF(1=1, "Yes", "No")');
Custom Autocomplete Sources
Shtumi\UsefulBundle\Form\Type\AjaxAutocompleteType to support non-entity data (e.g., API responses).Date Range Widgets
templates/ShtumiUsefulBundle/Form/date_range.html.twig.DQL Functions
Shtumi\UsefulBundle\Doctrine\DQL\AbstractFunction and registering them in the bundle’s Resources/config/doctrine.yaml.public function register()
{
$this->app->singleton('shtumi.useful.ajax_autocomplete', function ($app) {
return new \Shtumi\UsefulBundle\Service\AjaxAutocompleteService(
$app['doctrine.orm.entity_manager']
);
});
}
@stack('scripts') to load JS dependencies for autocomplete.How can I help you explore Laravel packages today?