CoolCMS API

ProductSetNameTranslator extends AbstractTranslator
in package

Maps a product set id to a decorative URL slug (the webalized `ProductSetText.name` in the link language).

The id is a regex capture of its own in the detail mask (<name>-s<id>); name is only SEO decoration. nameToId() is not used: ProductDetailRouteFactory::addStringTranslation always returns null when parsing and the route matches on id alone, so an old or foreign-language slug still leads to the right set.

IMPORTANT: the cache is per language, with a fallback to another language when a translation is missing (AbstractTranslator::fromCacheWithLanguageFallback()). A language-neutral cache ("last translated row wins") made every language link to the slug of whichever row loaded last.

Table of Contents

Properties

$idToNameCache  : array<int, array<int, string>>
$lazyLoadedIds  : array<int, true>
$localeResolver  : LocaleResolver
$productSetManager  : ProductSetManager
$warmedUp  : bool

Methods

__construct()  : mixed
addTargetFactory()  : void
Registers a route factory that uses this translator.
clearCache()  : void
Clears the cache.
getTargetFactories()  : array<string|int, string>
Returns the route factories that use this translator.
idToName()  : string|null
warmupCache()  : void
Preloads the cache.
warmupFromEntities()  : void
Preloads the cache from already loaded entities, without a database query.
fromCacheWithLanguageFallback()  : TValue|null
Returns a value from a translation cache, falling back to the other languages.

Properties

$idToNameCache

private array<int, array<int, string>> $idToNameCache = []

Cache id->name [languageId][productSetId] = webName

$lazyLoadedIds

private array<int, true> $lazyLoadedIds = []

product sets whose translations were already loaded individually

Methods

addTargetFactory()

Registers a route factory that uses this translator.

public addTargetFactory(string $factoryClass) : void

Called from the factory constructor as addTargetFactory($this::class).

Parameters
$factoryClass : string

fully qualified factory class name

getTargetFactories()

Returns the route factories that use this translator.

public getTargetFactories() : array<string|int, string>
Return values
array<string|int, string> —

factory class names without namespace

idToName()

public idToName(int $id, string $loc) : string|null
Parameters
$id : int
$loc : string
Return values
string|null

warmupCache()

Preloads the cache.

public warmupCache([array<string|int, int>|null $ids = null ]) : void
Parameters
$ids : array<string|int, int>|null = null

when null, loads all sady; otherwise only the given ones

warmupFromEntities()

Preloads the cache from already loaded entities, without a database query.

public warmupFromEntities(array<string|int, mixed> $productSets) : void
Parameters
$productSets : array<string|int, mixed>

ProductSet entities with loaded translations

fromCacheWithLanguageFallback()

Returns a value from a translation cache, falling back to the other languages.

protected fromCacheWithLanguageFallback(array<string|int, mixed> $cache, int $languageId, TKey $key) : TValue|null

IMPORTANT: without the fallback a translator returns null when the translation for the language is missing, and the route cannot build the URL at all ("No route for ..."). One untranslated category then breaks the whole foreign-language page, not just its own link.

Untranslated content shows in the main language instead of disappearing: the URL carries the main-language slug under /en/, until someone adds the translation.

Parameters
$cache : array<string|int, mixed>
$languageId : int
$key : TKey
Tags
template
Return values
TValue|null
On this page

Search results