time - typo3 viewhelper is only called once -
i have made own viewhelper getting external images (thanks robert pflamm see typo3 fluid image external resource). if use imageviewhelper working finde.
but if use \typo3\cms\fluid\viewhelpers\uri\imageviewhelper
image rendered once. same problem here typo3 ver. 7.6.2 - condition viewhelpers evaluated once. not know how solve it
can please help? martin
namespace mwxxx\mwxxx\viewhelpers; use typo3\cms\core\utility\generalutility; use typo3\cms\fluid\viewhelpers\uri\imageviewhelper; use typo3\cms\core\resource\fileinterface; use typo3\cms\extbase\domain\model\abstractfilefolder; class externalimageviewhelper extends \typo3\cms\fluid\viewhelpers\uri\imageviewhelper { const upload_directory = 'upload'; const temp_prefix = 'mwxx'; /** * resourcefactory * * @var \typo3\cms\core\resource\resourcefactory * @inject */ protected $resourcefactory = null; /** * resizes given image (if required) , renders respective img tag * * @see https://docs.typo3.org/typo3cms/typoscriptreference/contentobjects/image/ * * @param string $src path file, combined fal identifier or uid (integer). if $treatidasreference set, integer considered uid of sys_file_reference record. if got fal object, consider using $image parameter instead * @param string $width width of image. can numeric value representing fixed width of image in pixels. can perform simple calculations adding "m" or "c" value. see imgresource.width possible options. * @param string $height height of image. can numeric value representing fixed height of image in pixels. can perform simple calculations adding "m" or "c" value. see imgresource.width possible options. * @param integer $minwidth minimum width of image * @param integer $minheight minimum height of image * @param integer $maxwidth maximum width of image * @param integer $maxheight maximum height of image * @param boolean $treatidasreference given src argument sys_file_reference record * @param fileinterface|abstractfilefolder $image fal object * * @return string * @throws \exception * @throws \typo3\cms\core\resource\exception\insufficientfolderaccesspermissionsexception * @throws \typo3\cms\core\resource\exception\insufficientfolderwritepermissionsexception * @throws \typo3\cms\fluid\core\viewhelper\exception */ public function render($src = null, $image = null, $width = null, $height = null, $minwidth = null, $minheight = null, $maxwidth = null, $maxheight = null, $treatidasreference = false) { if (filter_var($src, filter_validate_url)) { $storage = $this->resourcefactory->getdefaultstorage(); if (!$storage->hasfolder(self::upload_directory)) { $storage->createfolder(self::upload_directory); } if (file_exists('fileadmin/upload/'.basename(basename($src)))) { #echo "die datei $filename existiert"; $src = 'fileadmin/upload/'.basename(basename($src)); } else { $externalfile = generalutility::geturl($src); if ($externalfile) { $tempfilename = tempnam(sys_get_temp_dir(), self::temp_prefix); $handle = fopen($tempfilename, "w"); fwrite($handle, $externalfile); fclose($handle); $uploadfolder = $storage->getfolder(self::upload_directory); #echo "die datei $filename existiert nicht"; $file = $uploadfolder->addfile($tempfilename, basename(basename($src)), 'changename'); $src = $file->getpublicurl(); #unlink($tempfilename); } else { throw new \exception(sprintf('external url % cannot accessed.', $src), 1473233519); } } } return parent::render($src, $image, $width, $height, $minwidth, $minheight, $maxwidth, $maxheight, $treatidasreference); } }
the viewhelpers not public api meant extensible custom viewhelpers!
the problem facing after 1st call, viewhelpers compiled , method renderstatic
used don't override.
the best solution copy code of parent class , extend abstractviewhelper
or abstracttagbasedviewhelper
Comments
Post a Comment