/** * @DI\Observe("rich_text_format_event_import") * * @param RichTextFormatEvent $event */ public function import(RichTextFormatEvent $event) { $text = $event->getText(); preg_match_all(self::REGEX_PLACEHOLDER, $text, $matches, PREG_SET_ORDER); $baseUrl = $this->router->getContext()->getBaseUrl(); foreach ($matches as $match) { $uid = (int) $match[1]; $parent = $this->formatter->findParentFromDataUid($uid); $el = $this->formatter->findItemFromUid($uid); $node = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneBy(['parent' => $parent, 'name' => $el['name']]); if ($node) { $resource = $this->resourceManager->getResourceFromNode($node); $toReplace = "<a href='{$baseUrl}/innova_path/player/{$resource->getId()}#'>{$node->getName()}</a>"; $text = str_replace($match[0], $toReplace, $text); $event->setText($text); } } }
/** * @DI\Observe("rich_text_format_event_import") * * @param RichTextFormatEvent $event */ public function import(RichTextFormatEvent $event) { $text = $event->getText(); preg_match_all(self::REGEX_PLACEHOLDER, $text, $matches, PREG_SET_ORDER); foreach ($matches as $match) { $imgdata = explode('@', $match[1]); $uid = (int) $imgdata[0]; //not really actually ~that would be the part before the first (@) $parent = $this->formatter->findParentFromDataUid($uid); $el = $this->formatter->findItemFromUid($uid); $node = $this->om->getRepository('ClarolineCoreBundle:Resource\\ResourceNode')->findOneBy(['parent' => $parent, 'name' => $el['name']]); if ($node) { $toReplace = $this->generateDisplayedUrlForTinyMce($node, $match); $text = str_replace($match[0], $toReplace, $text); } } $event->setText($text); }