Skip to content
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

Resolve tags by name instead of id #6

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SingleCategorySelectionPropertyResolver implements PropertyResolverInterfa
{
public function resolve(mixed $data, string $locale, array $params = []): ContentView
{
if (!\is_string($data) || '' === $data) {
if (!\is_int($data)) {
return ContentView::create([], $params);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</service>

<service id="sulu_category.single_category_selection_property_resolver"
class="Sulu\Bundle\CategoryBundle\Infrastructure\Sulu\Content\PropertyResolver\CategorySelectionPropertyResolver">
class="Sulu\Bundle\CategoryBundle\Infrastructure\Sulu\Content\PropertyResolver\SingleCategorySelectionPropertyResolver">

<tag name="sulu_content.property_resolver"/>
</service>
Expand Down
21 changes: 19 additions & 2 deletions src/Sulu/Bundle/MediaBundle/Resources/config/services_content.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<services>
<!-- Property Resolver -->
<service id="sulu_media.media_selection_property_resolver"
Expand All @@ -22,12 +22,29 @@
<tag name="sulu_content.property_resolver"/>
</service>

<service id="sulu_media.collection_selection_property_resolver"
class="Sulu\Bundle\MediaBundle\Infrastructure\Sulu\Content\PropertyResolver\CollectionSelectionPropertyResolver">
<tag name="sulu_content.property_resolver"/>
</service>

<service id="sulu_media.single_collection_selection_property_resolver"
class="Sulu\Bundle\MediaBundle\Infrastructure\Sulu\Content\PropertyResolver\SingleCollectionSelectionPropertyResolver">
<tag name="sulu_content.property_resolver"/>
</service>

<!-- Resource Loader -->
<service id="sulu_media.media_resource_loader"
class="Sulu\Bundle\MediaBundle\Infrastructure\Sulu\Content\ResourceLoader\MediaResourceLoader">
<argument type="service" id="sulu_media.media_manager"/>

<tag name="sulu_content.resource_loader" type="media"/>
</service>

<service id="sulu_media.collection_resource_loader"
class="Sulu\Bundle\MediaBundle\Infrastructure\Sulu\Content\ResourceLoader\CollectionResourceLoader">
<argument type="service" id="sulu_media.collection_manager"/>

<tag name="sulu_content.resource_loader" type="collection"/>
</service>
</services>
</container>
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function __construct(

public function load(array $ids, ?string $locale, array $params = []): array
{
$result = $this->tagRepository->findBy(['id' => $ids]);
$result = $this->tagRepository->findBy(['name' => $ids]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this migrated correctly by the phpcr migration bundle? Currently tags are stored as ids in the excerpt in phpcr.

Copy link
Owner Author

@Prokyonn Prokyonn Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't

But tbh I would like it more to save the id instead of the name, but then we would need to adjust it also on the FE 🤔

What would be the best way to go forward?


$mappedResult = [];
foreach ($result as $tag) {
$mappedResult[$tag->getId()] = $tag->getName();
$mappedResult[$tag->getName()] = $tag->getName();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about remove the loader if we just rereturn the names here.

}

return $mappedResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ public function testLoad(): void
$tag1 = $this->createTag(1);
$tag2 = $this->createTag(3);

$this->tagRepository->findBy(['id' => [1, 3]])->willReturn([
$this->tagRepository->findBy(['name' => ['Tag 1', 'Tag 3']])->willReturn([
$tag1,
$tag2,
])
->shouldBeCalled();

$result = $this->loader->load([1, 3], 'en', []);
$result = $this->loader->load(['Tag 1', 'Tag 3'], 'en', []);

$this->assertSame([
1 => $tag1->getName(),
3 => $tag2->getName(),
'Tag 1' => $tag1->getName(),
'Tag 3' => $tag2->getName(),
], $result);
}

Expand Down
Loading