-
-
Notifications
You must be signed in to change notification settings - Fork 222
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
FEATURE: Assets Eel helper for Neos.Media #4155
Conversation
I thought also about adding datasource to allow the selection of tags and collections, but that would require adding Neos as dependency to Neos.Media, which is Quatsch. But it would help a lot with making it possible to select Tags and Collections as node property combined with this helper. And currently the |
I would suggest creating separete methods for the respective ObjectType|string inputs, eg. |
i think we should follow the mentality of the new eel helpers for the ESCR ... idont know exactly how they look like, but they must have the same challenge of dtos vs primitives ... |
I would definitely hard suggest it there too 😂 |
And do you guys think I should add any other methods from the AssetRepo? |
There is not really a (new) mentality as far as I know. But I would suggest to see Eel helpers as adapters from the loosely typed fusion world into a strictly typed PHP world and therefore keep union types where it makes sense (i.e. where multiple variants mean the same thing). But I think @kitsunet's comment was re More concretely: I think this is totally fine and makes it easier to use a helper: function someHelper(SomeValueObject|string|null $foo): ?string {
if ($foo === null) {
return null;
}
if (is_string($foo)) {
$foo = SomeValueObject::fromString($foo);
}
// ... process
} While for the following I would suggest to split it up: function someHelper(SomeEntity|string|null $foo): ?string {
if ($foo === null) {
return null;
}
if (is_string($foo)) {
$foo = $this->someRepository->findByFoo($foo);
}
// ... process
} |
7763e71
to
6f4874e
Compare
This helper provides access to assets in Neos by either searching by Tag, AssetCollection, or a searchTerm combined with optionally Tags and an AssetCollection.
6f4874e
to
c3197ef
Compare
As @bwaidelich and @kitsunet talked about it. Do we want to adjust the helper like the proposal? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @bwaidelich and @kitsunet talked about it.
We haven't really talked about it and I might have misinterpreted Christians point.
Do we want to adjust the helper like the proposal?
Actually my suggestion was to keep it separate methods.. But thinking about it again: Tags are a special entity (and IMO they should have never been an entity but a value object)
So maybe it makes sense to adjust findByTag()
to allow entity or string (=label) like Christian suggested because you won't have an instance of the tag in many places.
And maybe the same for findByCollection
.. I'm not sure
/** | ||
* @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 comment
The reason will be displayed to describe this comment to others. Learn more.
For this one it makes a lot of sense, too, IMO:
/** | |
* @param Tag[] $tags | |
* @return QueryResultInterface<AssetInterface> | null | |
*/ | |
public function search(string $searchTerm, array $tags = [], AssetCollection $collection = null): ?QueryResultInterface | |
/** | |
* @param Tag[]|string[] $tags | |
* @return QueryResultInterface<AssetInterface> | null | |
*/ | |
public function search(?string $searchTerm, array $tags = [], AssetCollection|string $collection = null): ?QueryResultInterface |
So I revert back to my first version that allowed both strings and objects for both methods? |
Sorry, I didn't follow this PR from the beginning and didn't know that this was the first version? |
OK, I think I finally understood Christians comment (I had read it looking at the current version). I'd say: Lets keep the separate methods as is. |
I dindt completely follow the discussion, but can we later extract the conclusion into an issue or something, so we know how to write eel helpers in the future and dont have to re discuss this again ^^ |
The asset helper can handle tags and collections as string and instances to make the API simpler.
As the repository does not support string arrays for the tags, we drop that.
The search does not work with tag labels, as the repository does not handle strings. If this is wanted, we need to transform all strings into tag instances first. Also added some tests. |
@bwaidelich Does this fit better? |
IMO it's great like this, but this is just my personal preference and @kitsunet opposed this solution if I got it right?
That's what I would expect to be honest, like: $tagInstances = array_filter(array_map(fn (string|Tag $tag) => is_string($tag) ? $this->tagRepository->findOneByLabel($tag) : $tag)); |
It's fine by me, even though with the null (why did that come into play?) it now looks pretty convoluted with the type hints. I just think this will be hard to refactor later and fall on our feet sooner or later 😆 but if you all are fine with this, lets do it. |
I'm not sure, but IMO it's a good idea to be fault tolerant in Eel helpers, i.e. don't throw an exception for |
Yes. Often people feed variables into helpers which are not set yet, so we should be gentle. |
@markusguenther I can make the tags adjustment in the search method later like we discussed. Thx for taking care of the PR while I was tripping. |
I made the changes but now wonder, whether I shouldn't add a new search method to the AssetsRepository as search by tag OR collection is pretty useless IMO. |
Wrote with @Sebobo yesterday, and we keep it as it is now. |
This helper provides access to assets in Neos by either searching by Tag, AssetCollection, or
a searchTerm combined with optionally Tags and an AssetCollection.
Review instructions
Add some assets to collections and tag them, then use the helpers in Fusion like this:
Checklist
FEATURE|TASK|BUGFIX
!!!
and have upgrade-instructions