Adding custom data to a Shopware 6 pagelet, according to the latest documentation can be done by calling addExtension
:
use Shopware\Storefront\Pagelet\Footer\FooterPageletLoadedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
public function addActiveProductCount(FooterPageletLoadedEvent $event): void
{
$event->getPagelet()->addExtension('product_count', $productCountResult);
But, although the release note upgrade instructions do not mention a deprecation of addExtension
, so does my IDE:
Method 'addExtension' is deprecated
public function ExtendableTrait::addExtension(string $name, ?Struct $extension) void
Adds a new extension struct into the class storage. The passed name is used as unique identifier and has to be stored too.
Deprecated: 5.6.0
Implements:
ExtendableInterface::addExtension
Declared in:
Shopware\Core\Framework\Struct\ExtendableTrait
Source: development/vendor/shopware/platform/src/Core/Framework/Struct/ExtendableTrait.php
Update: according to @cuong-huynh 's finding that the second parameter ($extension
) must not be null
anymore, I added a check to make sure we never pass null
, but the method is still marked as deprecated in my IDE.
Can someone either tell me which method to use instead and where to find the related documentation or else revert the deprecation flag in case addExtension
has been marked as deprecated by mistake (similar to EntityRepository recently).
CodePudding user response:
According to deprecated comment @deprecated tag:v6.5.0 - second param $extension will not allow null anymore
as I understood that we still use that function but the second param can not be null.