martinadamec/doctrine-behaviors

Integration of KnpLabs/DoctrineBehaviors to Nette\DI

v5.0.0 2020-04-21 21:13 UTC

README

Latest stable

Port of KnpLabs/DoctrineBehaviors to Nette DI

Supported behaviors:

  • Translatable

Install

Via Composer:

$ composer require martinadamec/doctrine-behaviors

Register extensions you need in config.neon:

extensions:
	translatable: Zenify\DoctrineBehaviors\DI\TranslatableExtension

Usage

Translatable

Setup your translator locale callback in config.neon:

translatable:
	currentLocaleCallable: [@Translator, getLocale]

Place trait to your entity:

class Article
{
	
	use Knp\DoctrineBehaviors\Model\Translatable\Translatable;
	// returns translated property for $article->getTitle() or $article->title
	use MartinAdamec\DoctrineBehaviors\Entities\Attributes\Translatable;

}

And its translation entity:

class ArticleTranslation
{
	
	use Knp\DoctrineBehaviors\Model\Translatable\Translation;

	/**
	 * @ORM\Column(type="string")
	 * @var string
	 */
	public $title;

}