Search by

phil / slug-bundle

phil

phil/slug in Symfony: named sluggers from the configuration, each a service to decorate, autowired by name, the phil_slug filter in Twig, and an optional Doctrine history of former slugs

Package info

github.com/parler-haut-interagir-librement/slug-bundle

Homepage

Type:symfony-bundle

pkg:composer/phil/slug-bundle

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.0-alpha 2026-11-11 04:05 UTC

This package is auto-updated.

Last update: 2026-11-11 06:17:01 UTC


README

Named sluggers declared in the configuration, autowired by name and usable in Twig.

phil/slug-bundle brings phil/slug into a Symfony application. The configuration names the sluggers an application needs, one per use, each with its locale, its longest slug and the leading words it drops. Each named slugger is a service of its own, so the application decorates it like any Symfony service, and the decorator takes its place everywhere. The default slugger autowires as Slugger, every named one as Slugger $<name>Slugger, and Sluggers holds them all by name. With Twig installed, the phil_slug filter makes a slug in a template. With the history enabled, the former slugs of each subject point to its current slug, so an old address can answer with a redirect.

Use it when a Symfony application makes slugs in more than one way, or wants the same slugger in its services and its templates: titles cut at 80 characters, directory names without their leading article. Outside Symfony, phil/slug alone builds the same sluggers by hand. No slugger drops words unless the configuration says so, since the articles of a language and a site's own prefixes are each application's choice.

The bundle holds no slug logic of its own. It turns each configured slugger into a TransliteratingSlugger, wrapped in a LeadingWordsRemoved when it lists leading words, and registers the aliases that make autowiring by argument name work.

Status

Part State
Named sluggers from the configuration, Sluggers, autowiring by name Implemented and tested
Decoration of a named slugger Implemented and tested
The phil_slug Twig filter Implemented and tested
The history of former slugs in a Doctrine DBAL table, optional Implemented and tested

Documentation

Document What it covers
Installation Requirements and registering.
Configuration The sluggers, their options, the default one.
Services The service ids, autowiring by name, decorating a slugger.
Twig The phil_slug filter.
History of former slugs The optional table of former slugs, recording a change, reading it for redirects.
Extension points What an application implements, configures, replaces or relies on.
Testing How the bundle is tested.
Reference Every type of the bundle.

Quick start

# config/packages/phil_slug.yaml
phil_slug:
    sluggers:
        default: ~
        directory:
            leading_words: [le, la, les, l, the]
public function __construct(private Slugger $directorySlugger) {}

$this->directorySlugger->slug('Les Gardiens')->value;   // 'gardiens'
<li data-sort-name="{{ name|phil_slug('directory') }}">{{ name }}</li>

Requirements

PHP 8.5 or later, Symfony 8.2 or later, phil/slug; Twig for the filter; doctrine/dbal for the history.

Contributing

Contributions are welcome on the PHIL monorepo: read the contribution guide and the code of conduct. Report a vulnerability privately, as the security policy explains, never in a public issue.

License

MIT, © Philippe Gamache, doing business as Le Gnome Archiviste; a Parler Haut Interagir Librement project. See LICENSE.