Conference URLs now use slugs instead of integer id
This commit is contained in:
@@ -6,8 +6,11 @@ use App\Repository\ConferenceRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Doctrine\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||
use Symfony\Component\String\Slugger\SluggerInterface;
|
||||
|
||||
#[ORM\Entity(repositoryClass: ConferenceRepository::class)]
|
||||
#[UniqueEntity('slug')]
|
||||
class Conference
|
||||
{
|
||||
#[ORM\Id]
|
||||
@@ -30,6 +33,9 @@ class Conference
|
||||
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'conference', orphanRemoval: true)]
|
||||
private Collection $comments;
|
||||
|
||||
#[ORM\Column(length: 255, unique: true)]
|
||||
private ?string $slug = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->comments = new ArrayCollection();
|
||||
@@ -44,6 +50,13 @@ class Conference
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function computeSlug(SluggerInterface $slugger)
|
||||
{
|
||||
if(!$this->slug || '-' === $this->slug) {
|
||||
$this->slug = (string)$slugger->slug((string)$this)->lower();
|
||||
}
|
||||
}
|
||||
|
||||
public function getCity(): ?string
|
||||
{
|
||||
return $this->city;
|
||||
@@ -109,4 +122,16 @@ class Conference
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSlug(): ?string
|
||||
{
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
public function setSlug(string $slug): static
|
||||
{
|
||||
$this->slug = $slug;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user