* * * * * * * ### Browser Support * * To have the widest Browser-Support you should consider using a polyfill like: * http://scottjehl.github.io/picturefill/ * * @author Marc Neuhaus , famelo * @package Vhs * @subpackage ViewHelpers\Media */ class PictureViewHelper extends AbstractTagBasedViewHelper { const SCOPE = 'FluidTYPO3\Vhs\ViewHelpers\Media\PictureViewHelper'; const SCOPE_VARIABLE_SRC = 'src'; const SCOPE_VARIABLE_DEFAULT_SOURCE = 'default-source'; /** * name of the tag to be created by this view helper * * @var string * @api */ protected $tagName = 'picture'; /** * Initialize arguments. * * @return void * @api */ public function initializeArguments() { parent::initializeArguments(); $this->registerArgument('src', 'string', 'Path to the image.', TRUE); $this->registerArgument('alt', 'string', 'Text for the alt tag.', TRUE); $this->registerArgument('title', 'string', 'Text for the alt tag.', FALSE); } /** * Render method * @return string * @throws Exception */ public function render() { $src = $this->arguments['src']; $this->viewHelperVariableContainer->addOrUpdate(self::SCOPE, self::SCOPE_VARIABLE_SRC, $src); $content = $this->renderChildren(); $this->viewHelperVariableContainer->remove(self::SCOPE, self::SCOPE_VARIABLE_SRC); if (FALSE === $this->viewHelperVariableContainer->exists(self::SCOPE, self::SCOPE_VARIABLE_DEFAULT_SOURCE)) { throw new Exception('Please add a source without a media query as a default.', 1438116616); } $defaultSource = $this->viewHelperVariableContainer->get(self::SCOPE, self::SCOPE_VARIABLE_DEFAULT_SOURCE); $defaultImage = new TagBuilder('img'); $defaultImage->addAttribute('src', $defaultSource); $defaultImage->addAttribute('alt', $this->arguments['alt']); if (FALSE === empty($this->arguments['title'])) { $defaultImage->addAttribute('title', $this->arguments['alt']); } $content .= $defaultImage->render(); $this->tag->setContent($content); return $this->tag->render(); } }