<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
locastic / api-platform-translation-bundle example snippets
php
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Locastic\ApiPlatformTranslationBundle\Model\TranslationInterface;
class Post extends AbstractTranslatable
{
// ...
protected function createTranslation(): TranslationInterface
{
return new PostTranslation();
}
}
php
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable;
use Symfony\Component\Serializer\Annotation\Groups;
class Post extends AbstractTranslatable
{
// ...
/**
* @Groups({"post_read"})
*/
private $title;
public function setTitle(string $title)
{
$this->getTranslation()->setTitle($title);
}
public function getTitle(): ?string
{
return $this->getTranslation()->getTitle();
}
}
php
use Symfony\Component\Serializer\Annotation\Groups;
use Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslation;
class PostTranslation extends AbstractTranslation
{
// ...
/**
* @ORM\ManyToOne(targetEntity="Post", inversedBy="translations")
*/
protected $translatable;
/**
* @ORM\Column(type="string")
*
* @Groups({"post_read", "post_write", "translations"})
*/
private $title;
/**
* @ORM\Column(type="string")
*
* @Groups({"post_write", "translations"})
*/
protected $locale;
public function setTitle(string $title): void
{
$this->title = $title;
}
public function getTitle(): ?string
{
return $this->title;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.