<?php<br><br>
$callable = array('My\Class', 'transliterationMethod');<br>
$sluggableListener->setTransliterator($callable);<br><br>
// or use a closure<br><br>
$callable = function($text, $separatorUsed, $objectBeingSlugged) {<br>
// ...<br>
return $transliteratedText;<br>
};<br>
$sluggableListener->setTransliterator($callable);<br>
<service id="stof_doctrine_extensions.listener.sluggable" class="%stof_doctrine_extensions.listener.sluggable.class%" public="false">
<call method="setAnnotationReader">
<argument type="service" id="annotation_reader" />
</call>
<call method="setTransliterator">
<argument type="collection">
<argument>\path\to\your\Urlizer</argument>
<argument>transliterate</argument>
</argument>
</call>
</service>
namespace YourBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class AddTransliterator implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$def = $container->findDefinition('stof_doctrine_extensions.listener.sluggable');
$def->addMethodCall('setTransliterator', [['YourBundle\\Transliterator\\Transliterator', 'transliterate']]);
}
}
# services.yml
app.transliterator:
class: AppBundle\Gedmo\Sluggable\SluggableTransliterator
arguments:
- @remedge.yandex_translate.manager
gedmo.listener.sluggable:
class: Gedmo\Sluggable\SluggableListener
tags:
- { name: doctrine.event_subscriber, connection: default }
calls:
- [ setAnnotationReader, [ @annotation_reader ] ]
- [ setTransliterator, [ [@app.transliterator, 'translate'] ] ]
# AppBundle/Gedmo/Sluggable/SluggableTransliterator.php
namespace AppBundle\Gedmo\Sluggable;
use Gedmo\Sluggable\Util\Urlizer;
use Remedge\YandexTranslateBundle\Manager\TranslateManager;
class SluggableTransliterator extends Urlizer
{
/** @var TranslateManager */
private $translator;
/**
* @param TranslateManager $translator
*/
public function __construct(TranslateManager $translator)
{
$this->translator = $translator;
}
public function translate($text, $separator = '-')
{
$text = $this->translator->translate($text, 'ru-en');
return self::urlize($text, $separator);
}
}