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

[StorageList & Slug] fixes for shared wishlist & slugs #2151

Merged
merged 4 commits into from
Dec 6, 2022
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
2 changes: 1 addition & 1 deletion .github/workflows/packages_components.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: "List Packages"
id: create-list
run: echo "packages=$(find src/CoreShop/Bundle -mindepth 2 -maxdepth 2 -type f -name composer.json -exec dirname '{}' \; | sed -e 's/src\/CoreShop\///g' | sort | jq --raw-input . | jq --slurp . | jq -c .)" >> $GITHUB_OUTPUT
run: echo "packages=$(find src/CoreShop/Component -mindepth 2 -maxdepth 2 -type f -name composer.json -exec dirname '{}' \; | sed -e 's/src\/CoreShop\///g' | sort | jq --raw-input . | jq --slurp . | jq -c .)" >> $GITHUB_OUTPUT

outputs:
packages: "${{ steps.create-list.outputs.packages }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ routes:
priority: 2

coreshop_wishlist_summary:
pattern: '/(\w+)\/shop\/wishlist(?:\/((.*)))$/'
reverse: '/%_locale/shop/wishlist/{%identifier}'
pattern: '/(\w+)\/shop\/wishlist(?:\/((.*)))?$/'
reverse: '/%_locale/shop/wishlist{/%identifier}'
controller: 'coreshop.storage_list.controller.wishlist:summaryAction'
variables: _locale,identifier
priority: 2
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,10 @@ services:
decorates: 'CoreShop\Component\Pimcore\Slug\DataObjectSlugGeneratorInterface'
arguments:
- '@CoreShop\Bundle\ResourceBundle\Slug\ResourceConfigurationSlugGenerator.inner'
- '@CoreShop\Component\Resource\Metadata\RegistryInterface'

CoreShop\Component\Resource\Pimcore\ResourceSlugLinkGenerator:
decorates: 'CoreShop\Component\Pimcore\Slug\SluggableLinkGenerator'
arguments:
- '@CoreShop\Component\Resource\Pimcore\ResourceSlugLinkGenerator.inner'
- '@CoreShop\Component\Resource\Metadata\RegistryInterface'
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function summaryAction(Request $request): Response
}

if (!$isSharedList && $list instanceof ShareableStorageListInterface && $list->listCanBeShared()) {
$params['share_link'] = $this->generateUrl($this->summaryRoute, ['token' => $list->getToken()], UrlGeneratorInterface::ABSOLUTE_URL);
$params['share_link'] = $this->generateUrl($this->summaryRoute, ['identifier' => $list->getToken()], UrlGeneratorInterface::ABSOLUTE_URL);
}

return $this->render($this->templateSummary, $params);
Expand Down
10 changes: 0 additions & 10 deletions src/CoreShop/Component/Pimcore/Slug/SluggableLinkGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
namespace CoreShop\Component\Pimcore\Slug;

use CoreShop\Component\Pimcore\Exception\LinkGenerationNotPossibleException;
use CoreShop\Component\Resource\Metadata\RegistryInterface;
use Pimcore\Http\Request\Resolver\SiteResolver;
use Pimcore\Model\DataObject\ClassDefinition\LinkGeneratorInterface;
use Pimcore\Model\DataObject\Concrete;
Expand All @@ -30,7 +29,6 @@ class SluggableLinkGenerator implements LinkGeneratorInterface
public function __construct(
private SiteResolver $siteResolver,
private RequestStack $requestStack,
private RegistryInterface $metadataRegistry,
) {
}

Expand All @@ -44,14 +42,6 @@ public function generate(Concrete $object, array $params = []): string
));
}

if ($this->metadataRegistry->hasClass($object::class)) {
$metadata = $this->metadataRegistry->getByClass($object::class);

if ($metadata->hasParameter('slug') && !$metadata->getParameter('slug')) {
throw new LinkGenerationNotPossibleException();
}
}

$slugs = $object->getSlug($params['_locale'] ?? null);
$slug = null;
$fallbackSlug = null;
Expand Down
3 changes: 2 additions & 1 deletion src/CoreShop/Component/Pimcore/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
}
],
"require": {
"pimcore/pimcore": "^10.5"
"pimcore/pimcore": "^10.5",
"laminas/laminas-stdlib": "^3.6"
},
"require-dev": {
"phpstan/phpstan": "^1.5.4",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

/*
* CoreShop
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - CoreShop Commercial License (CCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.org)
* @license https://www.coreshop.org/license GPLv3 and CCL
*
*/

namespace CoreShop\Component\Resource\Pimcore;

use CoreShop\Component\Pimcore\Exception\LinkGenerationNotPossibleException;
use CoreShop\Component\Pimcore\Slug\SluggableInterface;
use CoreShop\Component\Resource\Metadata\RegistryInterface;
use Pimcore\Model\DataObject\ClassDefinition\LinkGeneratorInterface;
use Pimcore\Model\DataObject\Concrete;

class ResourceSlugLinkGenerator implements LinkGeneratorInterface
{
public function __construct(
private LinkGeneratorInterface $inner,
private RegistryInterface $metadataRegistry,
) {
}

public function generate(Concrete $object, array $params = []): string
{
if (!$object instanceof SluggableInterface) {
throw new LinkGenerationNotPossibleException(
sprintf(
'Object with Path "%s" must implement %s',
$object->getFullPath(),
SluggableInterface::class,
)
);
}

if ($this->metadataRegistry->hasClass($object::class)) {
$metadata = $this->metadataRegistry->getByClass($object::class);

if ($metadata->hasParameter('slug') && !$metadata->getParameter('slug')) {
throw new LinkGenerationNotPossibleException();
}
}

return $this->inner->generate($object, $params);
}
}