src/App/Routing/SluggableTrait.php
public function generateSlug()
    {
        $translator = $this->translator();
        $languages  = $translator->availableLocales();
        $patterns   = $this->slugPattern();
        $curSlug    = $this->slug();
        $newSlug    = [];

        $origLang = $translator->getLocale();
        foreach ($languages as $lang) {
            $pattern = $patterns[$lang];

            $translator->setLocale($lang);
            if ($this->isSlugEditable() && isset($curSlug[$lang]) && strlen($curSlug[$lang])) {
                $newSlug[$lang] = $curSlug[$lang];
            } else {
                $newSlug[$lang] = $this->generateRoutePattern($pattern);
                if (!strlen($newSlug[$lang])) {
                    throw new UnexpectedValueException(sprintf(
                        'The slug is empty; the pattern is "%s"',
                        $pattern
                    ));
                }
            }
        }
        $translator->setLocale($origLang);

        return $translator->translation($newSlug);
    }
public function generateSlug()
    {
        $translator = $this->translator();
        $languages  = $translator->availableLocales();
        $patterns   = $this->slugPattern();
        $curSlug    = $this->slug();
        $newSlug    = [];

        $origLang = $translator->getLocale();
        foreach ($languages as $lang) {
            $pattern = $patterns[$lang];

            $translator->setLocale($lang);
            if ($this->isSlugEditable() && isset($curSlug[$lang]) && strlen($curSlug[$lang])) {
                $newSlug[$lang] = $curSlug[$lang];
            } else {
                $newSlug[$lang] = $this->generateRoutePattern($pattern);
                if (!strlen($newSlug[$lang])) {
                    throw new UnexpectedValueException(sprintf(
                        'The slug is empty; the pattern is "%s"',
                        $pattern
                    ));
                }
            }
        }
        $translator->setLocale($origLang);

        return $translator->translation($newSlug);
    }
public function generateSlug ( ) { $ translator = $ this -> translator ( ) ; $ languages = $ translator -> availableLocales ( ) ; $ patterns = $ this -> slugPattern ( ) ; $ curSlug = $ this -> slug ( ) ; $ newSlug = [ ] ; $ origLang = $ translator -> getLocale ( ) ; foreach ( $ languages as $ lang ) { $ pattern = $ patterns [ $ lang ] ; $ translator -> setLocale ( $ lang ) ; if ( $ this -> isSlugEditable ( ) && isset ( $ curSlug [ $ lang ] ) && strlen ( $ curSlug [ $ lang ] ) ) { $ newSlug [ $ lang ] = $ curSlug [ $ lang ] ; } else { $ newSlug [ $ lang ] = $ this -> generateRoutePattern ( $ pattern ) ; if ( ! strlen ( $ newSlug [ $ lang ] ) ) { throw new UnexpectedValueException ( sprintf ( 'The slug is empty; the pattern is "%s"' , $ pattern ) ) ; } } } $ translator -> setLocale ( $ origLang ) ; return $ translator -> translation ( $ newSlug ) ; }
Generate a URI slug from the object's URL slug pattern.

Note: This method bypasses routable affixes and {@see \Charcoal\Object\ObjectRoute}.

@see    RoutableTrait::generateSlug()
@throws UnexpectedValueException If the slug is empty.
@return Translation|string|null
Generate a URI slug from the object s URL slug pattern .