Download the PHP package tomchkk/transliterable-bundle without Composer
On this page you can find all versions of the php package tomchkk/transliterable-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tomchkk/transliterable-bundle
More information about tomchkk/transliterable-bundle
Files in tomchkk/transliterable-bundle
Package transliterable-bundle
Short Description A Symfony bundle providing an embeddable class, `Transliterable`, to enable mapping of a Doctrine entity field to `_original` and `_transliteration` columns within an entity.
License MIT
Informations about the package transliterable-bundle
TransliterableBundle
A Symfony bundle to facilitate the transliteration of Doctrine entity string fields.
Overview
TransliterableBundle provides an embeddable entity, Transliterable
, to enable mapping of a single Doctrine entity field to corresponding _original
and _transliteration
fields.
For example, a Doctrine entity class, Person
, with a $firstname
property mapped to the Transliterable
embedded entity will result in a table with firstname_original
and firstname_transliteration
columns.
Installation
- Require the latest stable version of TransliterableBundle by running the following console command from the root of your Symfony project:
$ composer require tomchkk/transliterable-bundle
- Enable the bundle by adding a reference to it in the array returned by
config/bundles.php
:
Usage
Embeddable Entity
An entity field can be made transliterable by including a Doctrine Embedded
annotation with a class value of the fully-qualified Transliterable
class name.
For the same reasons indicated in the documentation for Doctrine Embeddables, Transliterable
fields should be initialized to guarantee returning an embedded Transliterable
instance - e.g.:
Transliteration
An embbedded Transliterable
field with an original value but without a transliteration value will be transliterated when the entity is first persisted, or when updated.
Transliterator
By default TransliterableBundle uses PHP's built-in Transliterator class - decorated with a simple caching mechanism - as the transliteration engine. The default transliterator can be overridden in configuration by a custom service implementing Tomchkk\TransliterableBundle\Service\TransliteratorInterface
- e.g.:
Rulesets
In order to perform a transliteration the transliterator requires a ruleset identifier, which is used to create a particular transliterator instance. More on ruleset identifiers.
Global ruleset
The default transliterator provides a ruleset which will be applied to all transliterations if no other ruleset is provided; this default can be overridden by setting the global_ruleset
value in configuration - e.g.:
Annotation rulesets
A Transliterable
annotation is also available to enable a ruleset to be set at class- or property-level, the most specific of which will be applied to the transliteration of a field's value, overriding the global ruleset.
In the above example $firstname
would be transliterated according by the class ruleset; $lastname
by the property ruleset.
Frontend
Form Type
A TransliterableType
form type is included, providing an original
and transliteration
field - each extending Symfony's TextType. By default the required
option of the transliteration
field is set to false
since this field, if empty, will be populated when the entity is persisted.
The following configuration options are available for TransliterableType
:
Option | Type | Default | Use |
---|---|---|---|
exclude_transliteration |
boolean | false | Whether or not to exclude the transliteration field in the form |
options |
array | [empty] | Standard TextType options applicable to both TransliterableType fields |
original_options |
array | [empty] | Standard TextType options applicable to just the original field |
transliteration_options |
array | [empty] | Standard TextType options applicable to just the transliteration field |
Twig Extension
The transliterate
twig filter enables direct transliteration of strings within twig templates - e.g.:
The optional ruleset argument can be used per transliteration, otherwise the Transliterator service's global_ruleset
will be used:
All versions of transliterable-bundle with dependencies
doctrine/event-manager Version ^1.0
doctrine/orm Version ^2.6
doctrine/persistence Version ^1.1
symfony/config Version ^3.4 || ^4.2
symfony/dependency-injection Version ^3.4 || ^4.2
symfony/form Version ^3.4 || ^4.2
symfony/http-kernel Version ^3.4 || ^4.2
symfony/property-access Version ^3.4 || ^4.2
twig/twig Version ^2.6