Skip to content

Latest commit

 

History

History
60 lines (43 loc) · 2.15 KB

File metadata and controls

60 lines (43 loc) · 2.15 KB

SlugifyTransformer

Convert a string into a slug. The value is transliterated with a \Transliterator (by default, accents are removed), HTML tags are stripped, the result is trimmed and lowercased, every sequence of characters matching replace is replaced by separator, and leading and trailing separators are removed.

Requires the intl PHP extension.

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\String\SlugifyTransformer
  • Transformer code: slugify

Accepted inputs

string

Possible outputs

string

Options

Code Type Required Default Description
transliterator string 'NFD; [:Nonspacing Mark:] Remove; NFC' Transliterator identifier, passed to \Transliterator::create() (see Notes)
replace string '/[^a-z0-9]+/' Regular expression of the characters to replace (applied on the lowercased string)
separator string '_' Replacement string, also trimmed from both ends of the result

Examples

  • 'Hélène Dupont' becomes 'helene_dupont'
# Transformer options level
slugify: ~
  • Use a dash as separator, and also transliterate non-latin characters: 'Привет мир' becomes 'privet-mir'
# Transformer options level
slugify:
  transliterator: 'Any-Latin; Latin-ASCII'
  separator: '-'

Notes

An invalid transliterator identifier (rejected by \Transliterator::create()), or an option that is not a string, raises an InvalidOptionsException when the options are resolved, i.e. when the transformer is configured, not on the first transformed value.