> */ public function getEnabledParameters(): array { $enabled = []; foreach ($this->getConfig()['parameters'] as $key => $parameter) { if ($parameter['enabled'] && UtmParameterMode::DISABLED !== $parameter['mode']) { $enabled[$key] = $this->decorate($key, $parameter); } } return $enabled; } /** * Any catalog or custom parameter, whatever its state. Null when the key is unknown. * * @return array|null */ public function getParameter(string $key): ?array { $parameter = $this->getConfig()['parameters'][$key] ?? null; return null === $parameter ? null : $this->decorate($key, $parameter); } /** * Allowed values of a `dropdown` parameter. Always empty for `free` and `disabled` parameters. * * @return list */ public function getDropdownValues(string $key): array { $parameter = $this->getConfig()['parameters'][$key] ?? null; if (null === $parameter || UtmParameterMode::DROPDOWN !== $parameter['mode']) { return []; } return $parameter['values'] ?? []; } public function isLowercaseEnforced(): bool { return $this->getConfig()['enforce_lowercase']; } public function getSeparatorReplacement(): string { return $this->getConfig()['separator_replacement']; } /** * @return array{enforce_lowercase: bool, separator_replacement: string, parameters: array>} */ private function getConfig(): array { $raw = $this->coreParametersHelper->get(self::CONFIG_PARAMETER, []); // Upgrades keep their settings in local.php under a legacy key (the standalone // SmartlinksBundle wrote `smartlinks_utm_config`, the UtmManagerBundle before it // `utm_manager_config`); serve them until the Configuration page is saved again // (which writes the new key). foreach ([self::LEGACY_SMARTLINKS_PARAMETER, self::LEGACY_CONFIG_PARAMETER] as $legacyKey) { if (null === $raw || [] === $raw) { $legacy = $this->coreParametersHelper->get($legacyKey, []); if (null !== $legacy && [] !== $legacy) { $raw = $legacy; } } } return $this->normalizer->normalize($raw); } /** * @param array $parameter * * @return array */ private function decorate(string $key, array $parameter): array { $definition = $this->catalog->get($key); if ('' === $parameter['label']) { $parameter['label'] = null !== $definition ? $this->translator->trans($definition->getLabelKey()) : $key; } return ['key' => $key] + $parameter + [ 'group' => $definition?->group ?? UtmParameterCatalog::GROUP_CUSTOM, 'custom' => null === $definition, 'auto_generated' => $definition?->autoGenerated ?? false, ]; } }