Internal: Language: Add missing methods for self-reference one-to-many relation in Language entity - refs BT#21568

pull/5831/head
Angel Fernando Quiroz Campos 10 months ago
parent 33b068cb97
commit d04758ff2d
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 32
      src/CoreBundle/Entity/Language.php

@ -56,6 +56,9 @@ class Language
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)] #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)]
protected ?Language $parent = null; protected ?Language $parent = null;
/**
* @var Collection<int, self>
*/
#[Groups(['language:read', 'language:write'])] #[Groups(['language:read', 'language:write'])]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)] #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
protected Collection $subLanguages; protected Collection $subLanguages;
@ -113,18 +116,21 @@ class Language
return $this->available; return $this->available;
} }
public function setParent(self $parent): self public function setParent(?self $parent): static
{ {
$this->parent = $parent; $this->parent = $parent;
return $this; return $this;
} }
public function getParent(): ?self public function getParent(): ?static
{ {
return $this->parent; return $this->parent;
} }
/**
* @return Collection<int, self>
*/
public function getSubLanguages(): Collection public function getSubLanguages(): Collection
{ {
return $this->subLanguages; return $this->subLanguages;
@ -139,4 +145,26 @@ class Language
{ {
return $this->id; return $this->id;
} }
public function addSubLanguage(self $subLanguage): static
{
if (!$this->subLanguages->contains($subLanguage)) {
$this->subLanguages->add($subLanguage);
$subLanguage->setParent($this);
}
return $this;
}
public function removeSub(self $sub): static
{
if ($this->subLanguages->removeElement($sub)) {
// set the owning side to null (unless already changed)
if ($sub->getParent() === $this) {
$sub->setParent(null);
}
}
return $this;
}
} }

Loading…
Cancel
Save