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

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

            $this->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
                    ));
                }
            }
            $newSlug[$lang] = $this->finalizeSlug($newSlug[$lang]);

            $newRoute = $this->createRouteObject();
            $newRoute->setData([
                'lang'           => $lang,
                'slug'           => $newSlug[$lang],
                'route_obj_type' => $this->objType(),
                'route_obj_id'   => $this->id(),
            ]);

            if (!$newRoute->isSlugUnique()) {
                $newRoute->generateUniqueSlug();
                $newSlug[$lang] = $newRoute->slug();
            }
        }
        $this->translator()->setLocale($origLang);

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

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

            $this->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
                    ));
                }
            }
            $newSlug[$lang] = $this->finalizeSlug($newSlug[$lang]);

            $newRoute = $this->createRouteObject();
            $newRoute->setData([
                'lang'           => $lang,
                'slug'           => $newSlug[$lang],
                'route_obj_type' => $this->objType(),
                'route_obj_id'   => $this->id(),
            ]);

            if (!$newRoute->isSlugUnique()) {
                $newRoute->generateUniqueSlug();
                $newSlug[$lang] = $newRoute->slug();
            }
        }
        $this->translator()->setLocale($origLang);

        return $this->translator()->translation($newSlug);
    }
Generate a URL slug from the object's URL slug pattern.

@throws UnexpectedValueException If the slug is empty.
@return \Charcoal\Translator\Translation