GetSrcByPathViewHelper.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Opentalent\OtTemplating\ViewHelpers\Image;
  3. use Opentalent\OtCore\Exception\ApiRequestException;
  4. use Opentalent\OtCore\Service\OpentalentApiService;
  5. use Opentalent\OtCore\ViewHelpers\OtAbstractViewHelper;
  6. /**
  7. * Returns the absolute url of the requested image
  8. *
  9. * {namespace ot=Opentalent\OtTemplating\ViewHelpers}
  10. *
  11. * {ot:image.getByUrl(path: "/media/cache/crop_md/organization/123/upload/my_picture.jpg")}
  12. *
  13. * @see ot_core/Classes/Service/OpentalentImageService.php
  14. * @package Opentalent\OtTemplating\ViewHelpers
  15. */
  16. class GetSrcByPathViewHelper extends OtAbstractViewHelper
  17. {
  18. public OpentalentApiService $opentalentApiService;
  19. /**
  20. * @param OpentalentApiService $opentalentApiService
  21. * @return void
  22. */
  23. public function injectOpentalentApiService(OpentalentApiService $opentalentApiService)
  24. {
  25. $this->opentalentApiService = $opentalentApiService;
  26. }
  27. /**
  28. * -- This method is expected by Fluid --
  29. * Declares the viewhelper's parameters
  30. */
  31. public function initializeArguments()
  32. {
  33. $this->registerArgument(
  34. 'path',
  35. 'string',
  36. 'The path (relative url) of the image in the storage',
  37. true
  38. );
  39. }
  40. /**
  41. * -- This method is expected by Fluid --
  42. * Renders the content as html
  43. *
  44. * @return string
  45. * @throws ApiRequestException
  46. */
  47. public function render()
  48. {
  49. $path = $this->arguments['path'];
  50. return $this->opentalentApiService->getApiUri($path, true);
  51. }
  52. }