-
-
Notifications
You must be signed in to change notification settings - Fork 234
FEATURE: Assets Eel helper for Neos.Media #4155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
608c4d2
FEATURE: Assets eel helper for Neos.Media
Sebobo c3197ef
TASK: Adjust AssetsHelper method names and make them more precise
Sebobo 4c8568a
TASK: Simplify API to single methods
markusguenther 475db99
TASK: Remove string support for search helper
markusguenther cef002a
BUGFIX: Add missing collection instance for collection label
markusguenther ffa26f0
FEATURE: Adds functional tests for AssetHelper
markusguenther 19bbdbc
TASK: Adjust AssetsHelper search method to accept tags as strings
Sebobo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,124 @@ | ||||||||||||||||||||||
<?php | ||||||||||||||||||||||
|
||||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||||
|
||||||||||||||||||||||
namespace Neos\Media\Eel; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/* | ||||||||||||||||||||||
* This file is part of the Neos.Media package. | ||||||||||||||||||||||
* | ||||||||||||||||||||||
* (c) Contributors of the Neos Project - www.neos.io | ||||||||||||||||||||||
* | ||||||||||||||||||||||
* This package is Open Source Software. For the full copyright and license | ||||||||||||||||||||||
* information, please view the LICENSE file which was distributed with this | ||||||||||||||||||||||
* source code. | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
|
||||||||||||||||||||||
use Neos\Eel\ProtectedContextAwareInterface; | ||||||||||||||||||||||
use Neos\Flow\Annotations as Flow; | ||||||||||||||||||||||
use Neos\Flow\Persistence\Exception\InvalidQueryException; | ||||||||||||||||||||||
use Neos\Flow\Persistence\QueryResultInterface; | ||||||||||||||||||||||
use Neos\Media\Domain\Model\AssetCollection; | ||||||||||||||||||||||
use Neos\Media\Domain\Model\AssetInterface; | ||||||||||||||||||||||
use Neos\Media\Domain\Model\Tag; | ||||||||||||||||||||||
use Neos\Media\Domain\Repository\AssetCollectionRepository; | ||||||||||||||||||||||
use Neos\Media\Domain\Repository\AssetRepository; | ||||||||||||||||||||||
use Neos\Media\Domain\Repository\TagRepository; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* This is a helper for accessing assets from the media library | ||||||||||||||||||||||
* | ||||||||||||||||||||||
* @api | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
class AssetsHelper implements ProtectedContextAwareInterface | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @Flow\Inject | ||||||||||||||||||||||
* @var AssetRepository | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
protected $assetRepository; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @Flow\Inject | ||||||||||||||||||||||
* @var TagRepository | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
protected $tagRepository; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @Flow\Inject | ||||||||||||||||||||||
* @var AssetCollectionRepository | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
protected $assetCollectionRepository; | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @return QueryResultInterface<AssetInterface> | null | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function findByTag(?Tag $tag): ?QueryResultInterface | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (!$tag) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return $this->assetRepository->findByTag($tag); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @return QueryResultInterface<AssetInterface> | null | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function findByTagLabel(?string $tagLabel): ?QueryResultInterface | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (!$tagLabel) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
$tag = $this->tagRepository->findOneByLabel($tagLabel); | ||||||||||||||||||||||
return $this->findByTag($tag); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @return QueryResultInterface<AssetInterface> | null | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function findByCollection(?AssetCollection $collection): ?QueryResultInterface | ||||||||||||||||||||||
bwaidelich marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (!$collection) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
return $this->assetRepository->findByAssetCollection($collection); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @return QueryResultInterface<AssetInterface> | null | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function findByCollectionTitle(?string $collectionTitle): ?QueryResultInterface | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (!$collectionTitle) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
$collection = $this->assetCollectionRepository->findOneByTitle($collectionTitle); | ||||||||||||||||||||||
return $this->findByCollection($collection); | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @param Tag[] $tags | ||||||||||||||||||||||
* @return QueryResultInterface<AssetInterface> | null | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function search(string $searchTerm, array $tags = [], AssetCollection $collection = null): ?QueryResultInterface | ||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this one it makes a lot of sense, too, IMO:
Suggested change
|
||||||||||||||||||||||
{ | ||||||||||||||||||||||
if (!$searchTerm) { | ||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
try { | ||||||||||||||||||||||
return $this->assetRepository->findBySearchTermOrTags($searchTerm, $tags, $collection); | ||||||||||||||||||||||
} catch (InvalidQueryException) { | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
return null; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
/** | ||||||||||||||||||||||
* @param string $methodName | ||||||||||||||||||||||
*/ | ||||||||||||||||||||||
public function allowsCallOfMethod($methodName): bool | ||||||||||||||||||||||
{ | ||||||||||||||||||||||
return true; | ||||||||||||||||||||||
} | ||||||||||||||||||||||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.