Hallo,
ich habe zwei Möglichkeiten gesehen einen Produkt-Slider mit weiteren Informationen anzureichern und weiß nun nicht, welche Vorgehensweise korrekt ist. Beide führen zum Ergebnis. Aber welcher weg ist der richtige - vor allem im Hinblick auf Kompatbilität mit anderen Erweiterungen, die auch an dieser Stelle ansetzen.
Plugin XYZ:
<service id="PluginXYZ\Content\XYZProductSliderCmsElementResolver">
<argument type="service" id="Shopware\Core\Content\Product\Cms\ProductSliderCmsElementResolver"/>
<tag name="shopware.cms.data_resolver"/>
</service>
<?php declare(strict_types=1);
namespace PluginXYZ\Content;
use Shopware\Core\Content\Product\Cms\ProductSliderCmsElementResolver;
use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
use Shopware\Core\Content\Cms\DataResolver\Element\AbstractCmsElementResolver;
use Shopware\Core\Content\Cms\DataResolver\Element\ElementDataCollection;
use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
use Shopware\Core\Content\Cms\DataResolver\CriteriaCollection;
class XYZProductSliderCmsElementResolver extends AbstractCmsElementResolver
{
/** @var ProductSliderCmsElementResolver $elementResolver */
private $elementResolver;
public function __construct(ProductSliderCmsElementResolver $elementResolver)
{
$this->elementResolver = $elementResolver;
}
public function getType(): string
{
return $this->elementResolver->getType();
}
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
{
// Some Changes
}
public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
{
$this->elementResolver->enrich($slot, $resolverContext, $result);
}
}
Plugin-ABC
<service id="PluginABC\Content\ABCProductSliderCmsElementResolver" decorates="Shopware\Core\Content\Product\Cms\ProductSliderCmsElementResolver">
<argument type="service" id="PluginABC\Content\Product\Cms\ABCProductSliderCmsElementResolver.inner"/>
<tag name="shopware.cms.data_resolver"/>
</service>
<?php declare(strict_types=1);
namespace PluginABC\Content;
use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
use Shopware\Core\Content\Cms\DataResolver\Element\AbstractCmsElementResolver;
use Shopware\Core\Content\Cms\DataResolver\Element\CmsElementResolverInterface;
use Shopware\Core\Content\Cms\DataResolver\Element\ElementDataCollection;
use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
use Shopware\Core\Content\Cms\DataResolver\CriteriaCollection;
class ABCProductSliderCmsElementResolver extends AbstractCmsElementResolver
{
/** @var CmsElementResolverInterface $elementResolver */
private $elementResolver;
public function __construct(CmsElementResolverInterface $elementResolver)
{
$this->elementResolver = $elementResolver;
}
public function getType(): string
{
return $this->elementResolver->getType();
}
public function collect(CmsSlotEntity $slot, ResolverContext $resolverContext): ?CriteriaCollection
{
// Some Changes
}
public function enrich(CmsSlotEntity $slot, ResolverContext $resolverContext, ElementDataCollection $result): void
{
$this->elementResolver->enrich($slot, $resolverContext, $result);
}
}