StofDoctrineExtensionsBundle icon indicating copy to clipboard operation
StofDoctrineExtensionsBundle copied to clipboard

Adding a way to configure the slug generator

Open stof opened this issue 13 years ago • 12 comments

The extensions allow to use a custom slug generator but this is not supported in the bundle configuration yet.

stof avatar May 25 '11 19:05 stof

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.

stof avatar Jun 14 '11 09:06 stof

you can always get the sluggable listener as service and change transliterator.

l3pp4rd avatar Jun 14 '11 10:06 l3pp4rd

@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.

HelloGrayson avatar Jun 14 '11 14:06 HelloGrayson

@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.

HelloGrayson avatar Jun 14 '11 15:06 HelloGrayson

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 avatar Jun 25 '11 21:06 ruipenso

@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.

HelloGrayson avatar Jun 26 '11 05:06 HelloGrayson

Hi @merrix, my gist https://gist.github.com/1047590. Thanks in advance.

ruipenso avatar Jun 26 '11 12:06 ruipenso

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.

l3pp4rd avatar Jun 26 '11 13:06 l3pp4rd

Nice :) Thank you.

ruipenso avatar Jun 26 '11 13:06 ruipenso

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 ?

qpleple avatar Aug 25 '11 14:08 qpleple

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

l3pp4rd avatar Aug 25 '11 14:08 l3pp4rd

Thanks @l3pp4rd, this is working. Here is what it looks like for me now : https://gist.github.com/1170877

qpleple avatar Aug 25 '11 15:08 qpleple