Created action to set the togas for a short url

This commit is contained in:
Alejandro Celaya
2016-08-21 16:52:26 +02:00
parent 372488cbb4
commit 1da285a63a
7 changed files with 130 additions and 2 deletions

View File

@@ -16,6 +16,7 @@ trait TagManagerTrait
{
$entities = [];
foreach ($tags as $tagName) {
$tagName = $this->normalizeTagName($tagName);
$tag = $em->getRepository(Tag::class)->findOneBy(['name' => $tagName]) ?: (new Tag())->setName($tagName);
$em->persist($tag);
$entities[] = $tag;
@@ -23,4 +24,15 @@ trait TagManagerTrait
return new Collections\ArrayCollection($entities);
}
/**
* Tag names are trimmed, lowercased and spaces are replaced by dashes
*
* @param string $tagName
* @return string
*/
protected function normalizeTagName($tagName)
{
return str_replace(' ', '-', strtolower(trim($tagName)));
}
}