0

I'm making a form to create an event to be download as a file .ics to be used in calendars like google agenda. I have a description field which contain a description, a link of redirection to the website and a link for the a Visio if the event is programmed in remote. I want for my description field, this scheme of display :

"description of the event"

"link of the redirection"

"link of the Visio"

when I fill my field without line break It's perfect, but when I add a line break in the description, my last line of the description and the link of the redirection are glued and the link of the Visio is disappeared

for example :

"link of the"

"redirection""link of the redirection"

some code :

controller:

    public function export(Meeting $meeting, IcsProvider $ics): Response
    {
        $this->denyAccessUnlessGranted(MeetingVoter::VIEW, $meeting);
        $cal = $ics->createCalendar(null, true);
        $event = $cal->newEvent();
        $link = $this->generateUrl('meeting_show', ['slug' => $meeting->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);

        // Get link of redirect and Visio

        $description = $meeting->getDescription()."\n\n ".$link;
        if (!empty($meeting->getVisioLink())) {
            $description .= "\n\nLink of visio : " . $meeting->getVisioLink();
        }

        // Add links for documents
        if ($meeting->getDocuments()->count()) {
            $description .= "\n\n document of the event : ";
            foreach ($meeting->getDocuments() as $document) {
                $description .= "\n" . $this->generateUrl('document_open', ['slug' => $document->getSlug()], UrlGeneratorInterface::ABSOLUTE_URL);
            }
        }

        $event
            ->setStartDate($meeting->getBegin())
            ->setEndDate($meeting->getEnd())
            ->setName($meeting->getName())
            ->setDescription($description);

        // Add place
        if (!$meeting->getVisio() && !empty($meeting->getPlace())) {
            $event->setLocation($meeting->getPlace());
        }

        return new Response(
            $cal->returnCalendar(),
            200,
            array(
                'Content-Type' => 'text/calendar; charset=utf-8',
                'Content-Disposition' => 'attachment; filename="' . preg_replace('((^\.)|\/|(\.$))', '_', $meeting->getName()) . '.ics"',
            )
        );
    }

Form:

$builder
            ->add('name')
            ->add('begin', DateTimeType::class, [
                'widget' => 'single_text'
            ])
            ->add('end', DateTimeType::class, [
                'widget' => 'single_text'
            ])
            ->add('visio', CheckboxType::class, ['required' => false])
            ->add('visioLink', TextType::class, ['required' => false])
            ->add('place', TextType::class, ['required' => false])
            ->add('description', TextareaType::class)

I can't use nl2br, I see <br> tags on the calendar

Someone have an idea to how can I solve that issue ?

gp_sflover
  • 3,460
  • 5
  • 38
  • 48
yonea
  • 89
  • 6
  • yeah I found my solutions in answers, I edit my code to show the fix – yonea Mar 01 '22 at 18:22
  • You should never add any solution inside any question. Specially if it was close due to the duplicate, like in this case. – gp_sflover Mar 01 '22 at 20:33
  • I should add that it is OK to answer your own question when you find the answer. Although, in this case, probably better to leave is as "closed due to duplicate" – S. Dre Mar 02 '22 at 09:10

0 Answers0