-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Comments
how your entity model looks like? it should create it, but it cannot be unique as of translations |
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: |
trick with translatable slug is that \Gedmo\Sluggable\SluggableListener must be added to event subscriber before translatable listener |
I'm using stof bundle and I think it already puts the sluggable 2012/8/1 Luke reply@reply.github.com:
Daniele Cesarini RHCE #110-981-842 |
does standard way of persisting translations work fine for you? is this issue only valid for mentioned TranslatedFieldType? |
I tried only personal translations. I will try the "normal way" when i |
personal translations are fine but do u try to persist in standard way:
or only using TranslatedFieldType and AddTranslatedFieldSubscriber ? maybe its an issue with this subscriber not doctrine extensions itself |
I only use TranslatedFieldType and AddTranslatedFieldSubscriber. |
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 |
I have the some problem. Any solutions? |
+1 |
isn't it fixed by recent patches? |
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. |
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 |
Ok thanks for your time, I will investigate more deeply tomorrow. |
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. |
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:
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 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? @sercba @iJanki It's finally ok for you? oO |
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 |
Ok, thank you. |
I also need this feature |
Any updates? stof/StofDoctrineExtensionsBundle#276 |
What about hotfix/workaround? Is there any way to do it? |
doubt that there can be a solution, I do not invest much time in maintaining extensions.. |
I wish there was a solution for this |
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):
|
@taylankasap your gist is no longer available. Could you post the workaround again? Thanks! |
@andrewmy sorry, I can neither remember this issue nor the project I used that workaround on. |
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. |
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.
The text was updated successfully, but these errors were encountered: