Skip to content

Commit

Permalink
Merge pull request #2151 from dpfaffenbauer/features/2146
Browse files Browse the repository at this point in the history
[StorageList & Slug] fixes for shared wishlist & slugs
  • Loading branch information
dpfaffenbauer authored Dec 6, 2022
2 parents 193ec31 + a012551 commit f14a207
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 65 deletions.
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 @@ -238,7 +238,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);
}
}

0 comments on commit f14a207

Please sign in to comment.