From ea6654ada56e19967542bcabae6fe9e8bc09e1d1 Mon Sep 17 00:00:00 2001 From: Henrik Braune Date: Fri, 23 Sep 2016 15:20:50 +0200 Subject: [PATCH] Added serializer definition --- Entity/Language.php | 30 +++++++++++++++++++ .../config/serializer/Entity.Language.yml | 19 ++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 Resources/config/serializer/Entity.Language.yml diff --git a/Entity/Language.php b/Entity/Language.php index af456d0..e94bbec 100644 --- a/Entity/Language.php +++ b/Entity/Language.php @@ -125,4 +125,34 @@ public function createUniqueToken() { + /** + * An extra feature allows you to proxy translated fields of a translatable entity. + * + * @param string $method + * @param array $arguments + * + * @return mixed The translated value of the field for current locale + */ + protected function proxyCurrentLocaleTranslation($method, array $arguments = [], $fallback = false) + { + return call_user_func_array( + [$this->translate($this->getCurrentLocale(), $fallback), $method], + $arguments + ); + } + + + /** + * @return mixed + */ + public function getVirtualTitle() { + $value = $this->proxyCurrentLocaleTranslation('getTitle', array(), false); + if (!$value) { + $value = $this->translate($this->getDefaultLocale())->getTitle(); + } + return $value; + } + + + } diff --git a/Resources/config/serializer/Entity.Language.yml b/Resources/config/serializer/Entity.Language.yml new file mode 100644 index 0000000..8d05802 --- /dev/null +++ b/Resources/config/serializer/Entity.Language.yml @@ -0,0 +1,19 @@ +BrauneDigital\TranslationBaseBundle\Entity\Language: + exclusion_policy: ALL + read_only: false + access_type: public_method + virtual_properties: + getVirtualTitle: + serialized_name: title + type: string + expose: true + groups: ["default"] + + properties: + id: + expose: true + read_only: true + groups: ["default"] + code: + expose: true + groups: ["default"] \ No newline at end of file