/** * {@inheritDoc} */ public function filter($content, array $options = array()) { if ($this->blockProperty->getMetadata()->offsetExists('link')) { $element = $this->blockProperty->getMetadata()->get('link')->getReferencedElement(); if ($element !== null) { /* @var $element LinkReferencedElement */ if (!$element instanceof LinkReferencedElement) { // @TODO: any exception should be thrown probably return null; } // @TODO: the same code is inside HtmlFilter, should combine somehow. $title = ReferencedElementUtils::getLinkReferencedElementTitle($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); // @TODO: what if we failed to obtain the URL? $url = ReferencedElementUtils::getLinkReferencedElementUrl($element, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); $tag = new HtmlTag('a', $title ? $title : $url); $tag->setAttribute('title', $title)->setAttribute('href', $url)->setAttribute('class', $element->getClassName()); $target = $element->getTarget(); if (!empty($target)) { $tag->setAttribute('target', $target); } switch ($element->getResource()) { case LinkReferencedElement::RESOURCE_FILE: $tag->setAttribute('target', '_blank'); break; } return $tag; } } return null; }
/** * Parse supra.link, return beginning part of referenced link element. * * @param LinkReferencedElement $link * @return HtmlTagStart */ protected function parseSupraLinkStart(LinkReferencedElement $link) { $tag = new HtmlTagStart('a'); $title = ReferencedElementUtils::getLinkReferencedElementTitle($link, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); // @TODO: what if we failed to obtain the URL? $url = ReferencedElementUtils::getLinkReferencedElementUrl($link, $this->container->getDoctrine()->getManager(), $this->container->getLocaleManager()->getCurrentLocale()); $tag->setAttribute('title', $title)->setAttribute('href', $url)->setAttribute('class', $link->getClassName()); $target = $link->getTarget(); if (!empty($target)) { $tag->setAttribute('target', $target); } switch ($link->getResource()) { case LinkReferencedElement::RESOURCE_FILE: $tag->setAttribute('target', '_blank'); break; } return $tag; }