Advertisement
Guest User

Untitled

a guest
May 19th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <?php
  2. namespace My\Package\ResourceManagement\Target;
  3.  
  4. use Neos\Flow\Annotations as Flow;
  5. use Cocur\Slugify\Slugify;
  6. use Neos\Flow\ResourceManagement\ResourceMetaDataInterface;
  7. use Neos\Media\Domain\Repository\AssetRepository;
  8.  
  9. /**
  10. * A target which publishes resources by creating symlinks with the filename based on the files title.
  11. */
  12. class FileSystemSymlinkTarget extends \Neos\Flow\ResourceManagement\Target\FileSystemSymlinkTarget
  13. {
  14. /**
  15. * @Flow\Inject
  16. * @var AssetRepository
  17. */
  18. protected $assetRepository;
  19.  
  20. /**
  21. * @inheritDoc
  22. */
  23. protected function getRelativePublicationPathAndFilename(ResourceMetaDataInterface $object)
  24. {
  25. $filename = $object->getFilename();
  26.  
  27. $asset = $this->assetRepository->findOneByResourceSha1($object->getSha1());
  28.  
  29. if ($asset) {
  30. $slugify = new Slugify();
  31. if (!empty($asset->getTitle())) {
  32. $filename = $slugify->slugify($asset->getTitle()) . '.' . $asset->getFileExtension();
  33. }
  34. }
  35.  
  36. if ($object->getRelativePublicationPath() !== '') {
  37. $pathAndFilename = $object->getRelativePublicationPath() . $filename;
  38. } else {
  39. if ($this->subdivideHashPathSegment) {
  40. $sha1Hash = $object->getSha1();
  41. $pathAndFilename = $sha1Hash[0] . '/' . $sha1Hash[1] . '/' . $sha1Hash[2] . '/' . $sha1Hash[3] . '/' . $sha1Hash . '/' . $filename;
  42. } else {
  43. $pathAndFilename = $object->getSha1() . '/' . $filename;
  44. }
  45. }
  46. return $pathAndFilename;
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement