27 lines
704 B
PHP
27 lines
704 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\ComponentsBundle\GTM\PostMount;
|
|
|
|
use KupShop\ComponentsBundle\Twig\Components\Utils\GTM\Script;
|
|
use Symfony\UX\TwigComponent\Attribute\PostMount;
|
|
|
|
trait GTMPlaceholdersData
|
|
{
|
|
#[PostMount]
|
|
public function addGTMPlaceholdersData(array $componentsData): array
|
|
{
|
|
if (!Script::getGTMId()) {
|
|
return $componentsData;
|
|
}
|
|
|
|
if (method_exists($this, 'getGTMPlaceholders') && $data = $this->getGTMPlaceholders()) {
|
|
$data = json_encode($data, JSON_NUMERIC_CHECK | JSON_HEX_APOS);
|
|
$componentsData['data-gtm-placeholders'] = htmlentities($data);
|
|
}
|
|
|
|
return $componentsData;
|
|
}
|
|
}
|