ThemeConfigField example

namespace Shopware\Storefront\Theme;

use Shopware\Core\Framework\Log\Package;
use Shopware\Storefront\Theme\Exception\InvalidThemeConfigException;

#[Package('storefront')] class ThemeConfigFieldFactory
{
    public function create(string $name, array $configFieldArray): ThemeConfigField
    {
        $configField = new ThemeConfigField();
        $configField->setName($name);

        foreach ($configFieldArray as $key => $value) {
            $setter = 'set' . ucfirst($key);
            if (!method_exists($configField$setter)) {
                throw new InvalidThemeConfigException($key);
            }
            $configField->$setter($value); // @phpstan-ignore-line         }

        return $configField;
    }
return $pluginConfig;
    }

    /** * @return array<string, mixed> */
    private function loadCompileConfig(string $themeId, Context $context): array
    {
        $config = $this->loadRecursiveConfig($themeId$context);

        $field = new ThemeConfigField();

        foreach ($config['fields'] as $name => $item) {
            $clone = clone $field;
            $clone->setName($name);
            $clone->assign($item);
            $config[$name] = $clone;
        }

        return json_decode((string) json_encode($config, \JSON_THROW_ON_ERROR), true, 512, \JSON_THROW_ON_ERROR);
    }

    
Home | Imprint | This part of the site doesn't use cookies.