StofDoctrineExtensionsBundle
StofDoctrineExtensionsBundle copied to clipboard
Adding a way to configure the slug generator
The extensions allow to use a custom slug generator but this is not supported in the bundle configuration yet.
The sluggable listener is registered when using the bundle. The point here is adding a way to configure the transliterator used instead of always using the default one.
you can always get the sluggable listener as service and change transliterator.
@stof aah I see. I was getting an error, so I must not have been doing something right. Do you need to do something config-wise to get the listener to register with the bundle? I must be missing something.
@stof. Looks like I didn't activate the extension for the orm entity manager. After searching and being stuck for a day, I'd say this is a common gotcha for new adopters. Do you mind if I put a small note about the exception you would get if you didn't configure correctly in the documentation? This would have saved me alot of time and future searches on the subject would be cleared up at the source. I'll submit the pull if that's cool.
The bundle already handles setting the slug? I've searched thought the past issues, and I'm having the same problem as the issue #23 (Column 'slug' cannot be null). Any help? :) Thanks.
@ruipenso please post a gist with your config.yml entry for stof_doctrine_extensions
, you're entity, and the place where you are persisting the entity.
Hi @merrix, my gist https://gist.github.com/1047590. Thanks in advance.
The problem is in annotations:
use Gedmo\Mapping\Annotation as Gedmo;
and when use same style for annotating your properties:
@Gedmo\Sluggable
or
@Gedmo\Slug(separator="-", unique=true)
The annotation mapping was not updated in blog, and docs since it is quite new implementation and users haven't migrated yet.
Nice :) Thank you.
I am trying to find a workaround for the bug in slug generation of DoctrineExtensions library (https://github.com/l3pp4rd/DoctrineExtensions/issues/27).
In the thread, @l3pp4rd said that changing the transliterator function could fix the bug by calling:
$sluggableListener->setTransliterator(array('Gedmo\Sluggable\Util\Urlizer', 'urlize'));
I tried to override the service and add a method call to setTransliterator
by declaring in my bundle config/services.xml
:
<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>Gedmo\Sluggable\Util\Urlizer</argument>
<argument>urlize</argument>
</argument>
</call>
</service>
But it does not work because I get at first slug generation:
Integrity constraint violation: 1048 Column 'slug' cannot be null
Do you have any ideas ?
if overriding does not work, you can extend sluggable listener with new class, and in constructor set the transliterator callable. I do not know how DIC prioritizes these services :) read stof docs how to set custom listener classes
Thanks @l3pp4rd, this is working. Here is what it looks like for me now : https://gist.github.com/1170877