Skip to content

Instantly share code, notes, and snippets.

@nezaniel
Created August 12, 2016 09:18
Show Gist options
  • Save nezaniel/588973194e64c986fc87c703bb4f2d50 to your computer and use it in GitHub Desktop.
Save nezaniel/588973194e64c986fc87c703bb4f2d50 to your computer and use it in GitHub Desktop.
A TagBasedAssetListImplementation for Neos TypoScript 2
class TagBasedImageListImplementation extends TemplateImplementation {
/**
* @Flow\Inject
* @var TagRepository
*/
protected $tagRepository;
/**
* @Flow\Inject
* @var ImageRepository
*/
protected $imageRepository;
/**
* @return ImageInterface[]
*/
public function getImages() {
$tagIdentifier = $this->tsValue('tag');
if (!empty($tagIdentifier) && ($tag = $this->tagRepository->findByIdentifier($tagIdentifier)) instanceof Tag) {
/** @var Tag $tag */
return $this->imageRepository->findByTag($tag);
} else {
return [];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment