Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

personal translations and sluggable #415

Closed
danielec7 opened this issue Jul 30, 2012 · 28 comments
Closed

personal translations and sluggable #415

danielec7 opened this issue Jul 30, 2012 · 28 comments

Comments

@danielec7
Copy link

Hello,

I'm using personal translations and a sluggable field. When I insert a record I get the slug only for default locale. The slug for other locales is not created.
How is it supposed to work?

Thanks.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Jul 30, 2012

how your entity model looks like? it should create it, but it cannot be unique as of translations

@danielec7
Copy link
Author

Here are my entities:

<?php

namespace App\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="App\MyBundle\Entity\CheckListTagRepository")
 * @Gedmo\TranslationEntity(class="App\MyBundle\Entity\CheckListTagTranslation")
 */
class CheckListTag
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string $name
     * @Gedmo\Translatable
     * @ORM\Column(name="name", type="string", length=100)
     */
    private $name;

    /**
     * @var string $slug
     *
     * @Gedmo\Translatable
     * @Gedmo\Slug(fields={"name"})
     * @ORM\Column(name="slug", type="string", length=100, unique=true)
     */
    private $slug;

    /**
     * @ORM\OneToMany(
     *     targetEntity="CheckListTagTranslation",
     *     mappedBy="object",
     *     cascade={"persist", "remove"}
     * )
     */
    private $translations;

    public function __toString()
    {
        return $this->name;
    }

    public function __construct()
    {
        $this->translations = new \Doctrine\Common\Collections\ArrayCollection();
    }

    public function getTranslations()
    {
        return $this->translations;
    }

    public function addTranslation(CheckListTagTranslation $t)
    {
        if (!$this->translations->contains($t)) {
            $this->translations[] = $t;
            $t->setObject($this);
        }
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     */
    public function setName($name)
    {
        $this->name = $name;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Get slug
     *
     * @return string 
     */
    public function getSlug()
    {
        return $this->slug;
    }
}
<?php

namespace App\MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation;

/**
 * @ORM\Table(name="check_list_tag_translations",
 *     uniqueConstraints={@ORM\UniqueConstraint(name="lookup_unique_idx", columns={
 *         "locale", "object_id", "field"
 *     })}
 * )
 * @ORM\Entity
 */

class CheckListTagTranslation extends AbstractPersonalTranslation
{
    public function __construct($locale, $field, $value)
    {
        $this->setLocale($locale);
        $this->setField($field);
        $this->setContent($value);
    }

    /**
      * @ORM\ManyToOne(targetEntity="CheckListTag", inversedBy="translations")
      * @ORM\JoinColumn(name="object_id", referencedColumnName="id", onDelete="CASCADE")
      */
    protected $object;
}

To create entities I use a form with a listener as described here:

https://gist.github.com/3133085

@Venzon
Copy link

Venzon commented Aug 1, 2012

trick with translatable slug is that \Gedmo\Sluggable\SluggableListener must be added to event subscriber before translatable listener
check your container class and see how does it look there

@danielec7
Copy link
Author

I'm using stof bundle and I think it already puts the sluggable
before. It doesn't work only for the translation. The main entity gets
its slug.

2012/8/1 Luke reply@reply.github.com:

trick with translatable slug is that \Gedmo\Sluggable\SluggableListener must be added to event subscriber before translatable listener
check your container class and see how does it look there


Reply to this email directly or view it on GitHub:
https://github.com/l3pp4rd/DoctrineExtensions/issues/415#issuecomment-7422301

Daniele Cesarini

RHCE #110-981-842
Blog: http://www.cesarini.it
http://www.facebook.com/sysadmin.developer
https://twitter.com//iJanki
https://plus.google.com/107548465192931758089/

@Venzon
Copy link

Venzon commented Aug 1, 2012

does standard way of persisting translations work fine for you? is this issue only valid for mentioned TranslatedFieldType?

@danielec7
Copy link
Author

I tried only personal translations. I will try the "normal way" when i
have time.

@Venzon
Copy link

Venzon commented Aug 1, 2012

personal translations are fine but do u try to persist in standard way:

$article = $em->find('Entity\Article', 1 /*article id*/);
$article->setTitle('my title in de');
$article->setContent('my content in de');
$article->setTranslatableLocale('de_de'); // change locale
$em->persist($article);
$em->flush();

or only using TranslatedFieldType and AddTranslatedFieldSubscriber ?

maybe its an issue with this subscriber not doctrine extensions itself

@danielec7
Copy link
Author

I only use TranslatedFieldType and AddTranslatedFieldSubscriber.
And By the way I don't have setTranslatableLocale in my entity. Does
it work for personal translations?

@Venzon
Copy link

Venzon commented Aug 1, 2012

It worked for me some time ago and now it also switch locale of my personal entity but I have problem with persisting personal translations https://github.com/l3pp4rd/DoctrineExtensions/issues/421

@sercba
Copy link

sercba commented Oct 3, 2012

I have the some problem. Any solutions?

@djozen
Copy link

djozen commented Oct 20, 2012

+1

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Nov 3, 2012

isn't it fixed by recent patches?

@webda2l
Copy link

webda2l commented Mar 11, 2013

Doesn't work for me... Someone else or ?!

All my metadata of PersonnalTranslation classes (by example CategoryTranslation$GEDMO_SLUGGABLE_CLASSMETADATA) have an empty array as config.
So, no slug are generated for theses objects..

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 11, 2013

if its cached first clear all this orm cache and make sure listener is attached. It works for thausands so I'm sure its an error on your side

@webda2l
Copy link

webda2l commented Mar 11, 2013

Ok thanks for your time, I will investigate more deeply tomorrow.
Erase my dev environnement folder and "php app/console doctrine:cache:clear-metadata" give me same result. I don't have APC or other. Listeners are thoses of StofBundle, and are executed in the right order Sluggable first.

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 11, 2013

ah wait I misunderstood the issue, personal translations, if you generate them separately without setting a value for property which is sluggable, of course it cannot work, because it does not track a separate object. But it is just for sluggable behavior, configuration should be still populated.

@webda2l
Copy link

webda2l commented Mar 12, 2013

No I have got a similar code to https://github.com/l3pp4rd/DoctrineExtensions/issues/415#issuecomment-7383417, without the utility of a constructor in my PersonnalTranslation, and with exactly:

/**
 * @var string $slug
 *
 * @ORM\Column(name="slug", type="string", length=100, unique=true)
 * @Gedmo\Translatable
 * @Gedmo\Slug(fields={"title"})
 */
private $slug;

During the onFlush method of the SluggableListener, sluggable metadata about my PersonnalTranslation class (CategoryTranslation by example) are empty, so generateSlug() can't be apply with this object
In my mind, these missing sluggable metadata could be extracted from the native class (Category by example) and the generateSlug could be apply with some modifications for this case.
//// After reflection, not so easy because for the slug generation from other fields and the uniqueness, it requires process others PersonnalTranslation objects modified at the same time or not...

In any case, we are ok that is not implemented and the answer to your question https://github.com/l3pp4rd/DoctrineExtensions/issues/415#issuecomment-10041794 is no, or I have missed something, really?
I have searched test about PersonnalTranslation with sluggable field without success.

@sercba @iJanki It's finally ok for you? oO
@l3pp4rd I thank you for your work and am well aware that you no longer want spend too much time maintaining this bundle

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Mar 12, 2013

you are right, also it would be very hard to make extensions compatible with each other because these event listeners modify the same objects in UOW. Also the feature stack on orm grows with so many extension points that it may cause completely different things to fail, like other event listeners or filters

@webda2l
Copy link

webda2l commented Mar 13, 2013

Ok, thank you.
I hope a solution will be find for further development and not only maintenance.
It's strange that no more people need this feature.
Become an official Doctrine project (http://www.doctrine-project.org/projects.html) with some support of company to allocated team time or give some fund will be nice..

@dkorsak
Copy link

dkorsak commented Jun 6, 2013

I also need this feature

@ghost
Copy link

ghost commented Sep 11, 2015

Any updates? stof/StofDoctrineExtensionsBundle#276

@taylankasap
Copy link
Contributor

What about hotfix/workaround? Is there any way to do it?

@l3pp4rd
Copy link
Contributor

l3pp4rd commented Dec 11, 2015

doubt that there can be a solution, I do not invest much time in maintaining extensions..

@lunetics
Copy link

I wish there was a solution for this

@taylankasap
Copy link
Contributor

My manual solution: https://gist.github.com/taylankasap/7c2cc1c997bf73c532a4

Of course since this is only a workaround it doesn't do more than what I need. E.g. if you customize the @gedmo\Sluggable annotation you also need to customize the TranslatableSlugManager.

Usage inside controller goes like this, after flush (both create & update):

$this->get('app.doctrine.translatable_slug_manager')->updateTranslations($entity, 'AppBundle:PostTranslation');

@andrewmy
Copy link

@taylankasap your gist is no longer available. Could you post the workaround again? Thanks!

@taylankasap
Copy link
Contributor

@andrewmy sorry, I can neither remember this issue nor the project I used that workaround on.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Nov 25, 2021
alexander-schranz pushed a commit to alexander-schranz/DoctrineExtensions that referenced this issue Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests