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

Programmaticaly tags addition #7

Open
sc0rp10 opened this issue Jan 9, 2018 · 3 comments
Open

Programmaticaly tags addition #7

sc0rp10 opened this issue Jan 9, 2018 · 3 comments

Comments

@sc0rp10
Copy link

sc0rp10 commented Jan 9, 2018

Hi!
Nice and clear bundle, thank you for your work!
I have problem/proposition: I need to add/remove tags from my services.
Now, bundle only allow to add tags via listener.
What do you think, @garak it will be better, if we can have some service that manages tags and its relations?
Inside listener we can call such service and avoid copypasting.
If you agreed my idea, I can try to PR it.

@garak
Copy link
Member

garak commented Jan 10, 2018

I'm not sure to understand your use case. You can add/remove tags without using bundle's functionality, just relying on normal Doctrine entities relations.

@antoine-nedelec
Copy link

I has the same problem, here is how I solved it:
I first get my tag entity I want to add, then I try to save the entity:

    $tag = $this->getDoctrine()->getRepository(Tag::class)->find($id);
    if(!$entity->hasTag($destinationTag)) {
        $entity->addTag($destinationTag);
    }
    // THIS NEXT LINE IS MANDATORY, DOESN'T WORK IF THE FIELD "UPDATED" IS NOT UPDATED
    $entity->setTagsText($entity->getTagsText());
    $entityManager = $this->getDoctrine()->getManager();
    $entityManager->persist($entity);
    $entityManager->flush();

I am talking about this field in my entity:

    /**
     * @ORM\Column(type="datetime", nullable=true)
     */
    private $updated;

That is updated with the function in the same entity:

    /**
     * @param string
     */
    public function setTagsText($tagsText)
    {
        $this->tagsText = $tagsText;
        $this->updated = new \DateTime();
    }

I guess it's just not very user friendly to use 2 functions to update 1 tag, but maybe there is another way ?

@garak
Copy link
Member

garak commented Dec 6, 2018

@antoine-nedelec what about calling $this->updated = new \DateTime(); inside addTag mehod?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants