From 481950093fc3da1015f4ba3ff8dbbf4faa5ae2fc Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 15 Jan 2025 13:18:50 +0100 Subject: [PATCH] Update LocalizedContentInterface to allow removal of locales --- src/Entity/Interface/LocalizedContentInterface.php | 7 +++++++ src/Entity/Trait/LocalizedContent.php | 12 ++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Entity/Interface/LocalizedContentInterface.php b/src/Entity/Interface/LocalizedContentInterface.php index 4ae11c3..0dc6338 100644 --- a/src/Entity/Interface/LocalizedContentInterface.php +++ b/src/Entity/Interface/LocalizedContentInterface.php @@ -13,6 +13,8 @@ use Gedmo\Translatable\Translatable; */ interface LocalizedContentInterface extends Translatable { + public function getId(): ?int; + /** * Set the locale of the working content for translations. */ @@ -28,6 +30,11 @@ interface LocalizedContentInterface extends Translatable */ public function addLocale(string $locale): static; + /** + * Remove from the list of available translation locales. + */ + public function removeLocale(string $locale): static; + /** * Set the list of available translation locales. */ diff --git a/src/Entity/Trait/LocalizedContent.php b/src/Entity/Trait/LocalizedContent.php index e2c9628..4a5d7dd 100644 --- a/src/Entity/Trait/LocalizedContent.php +++ b/src/Entity/Trait/LocalizedContent.php @@ -32,6 +32,18 @@ trait LocalizedContent return $this; } + public function removeLocale(string $locale): static + { + $needle = $locale; + + $this->locales = [...\array_filter($this->locales, function (string $locale) use ($needle) { + return $locale !== $needle; + })]; + + return $this; + } + + public function setLocales(array $locales): static { $this->locales = $locales;