Skip to content

Commit

Permalink
Added serializer definition
Browse files Browse the repository at this point in the history
  • Loading branch information
hbraune committed Sep 23, 2016
1 parent 7f4f17f commit ea6654a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
30 changes: 30 additions & 0 deletions Entity/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}



}
19 changes: 19 additions & 0 deletions Resources/config/serializer/Entity.Language.yml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit ea6654a

Please sign in to comment.