Neos\Media\Domain\Repository\AssetRepository::findByTag PHP Метод

findByTag() публичный Метод

Find Assets with the given Tag assigned
public findByTag ( Tag $tag, AssetCollection $assetCollection = null ) : Neos\Flow\Persistence\QueryResultInterface
$tag Neos\Media\Domain\Model\Tag
$assetCollection Neos\Media\Domain\Model\AssetCollection
Результат Neos\Flow\Persistence\QueryResultInterface
    public function findByTag(Tag $tag, AssetCollection $assetCollection = null)
    {
        $query = $this->createQuery();
        $query->matching($query->contains('tags', $tag));
        $this->addImageVariantFilterClause($query);
        $this->addAssetCollectionToQueryConstraints($query, $assetCollection);
        return $query->execute();
    }

Usage Example

 /**
  * @param Tag $tag
  * @return void
  */
 public function deleteTagAction(Tag $tag)
 {
     $taggedAssets = $this->assetRepository->findByTag($tag);
     foreach ($taggedAssets as $asset) {
         $asset->removeTag($tag);
         $this->assetRepository->update($asset);
     }
     $this->tagRepository->remove($tag);
     $this->addFlashMessage('tagHasBeenDeleted', '', Message::SEVERITY_OK, [htmlspecialchars($tag->getLabel())]);
     $this->redirect('index');
 }