Skip to content

Multi-Language (MUI) Translation Pattern ​

Flow ID: SY-23 | Type: Shared Pattern | Complexity: Medium Last Updated: 2026-10-02 — 4.125.0 resync: MUI update is now a per-language in-place upsert (BaseMuiWriteRepository::upsertForEntity(), replaces delete + re-insert), TracksPresentColumns on MuiWriteData, shared FilterByTranslation, QueryFailedException wrap, Variation translations keyed by group_id; previous: 2026-06-13

Business Overview ​

The MUI (Multi-User Interface / Multi-Language) pattern is the platform's standard approach for storing and retrieving translated content. Every entity that needs localized text -- product names, category descriptions, badge labels, SEO metadata, blog articles -- follows the same companion-table pattern: a master table holds language-independent data, and a _mui companion table holds one row per language per master record.

This pattern is used by 38+ domain entities across the codebase, spanning both the legacy HMVC layer and the modern Domain/REST layer. Any admin flow that manages translatable content relies on MUI.

Why a shared pattern doc: Rather than repeating the MUI mechanics in every flow document, individual flow docs (AD-02, AD-05, AD-25, etc.) reference this document for the translation lifecycle details.


Architecture ​

Database Schema Convention ​

Every MUI-enabled entity follows the same two-table structure:

shop_product_badges          (master table)
  id            PK
  name          language-independent field
  badge         language-independent field

shop_product_badges_mui      (companion table)
  id            PK
  badge_id      FK -> shop_product_badges.id
  badge_text    translated field
  lang          VARCHAR(2), language code (e.g. 'el', 'en')

Naming rules:

  • Companion table name = {master_table}_mui
  • Foreign key column name = {singular_entity}_id (e.g. badge_id, category_id, product_id)
  • The lang column stores ISO 639-1 two-letter language codes
  • Composite index on ({fk_column}, lang) for efficient lookups

Field distribution: Language-independent data (IDs, prices, flags, sort orders, dates, foreign keys, image filenames) stays in the master table. Translated text (names, descriptions, slugs, SEO metadata, URLs) goes in the _mui table.

Entities With Complex MUI Tables ​

Simple entities like Badges have only one translated field (badge_text). Content-rich entities have many:

EntityMUI Fields
Productname, slug, description, short_description, ingredients, usage, extra_description, meta_title, meta_keywords, meta_description, url, redirect_url, video
Categoryname, slug, fulltext, extra_description, meta_title, meta_keywords, meta_description, url, redirect_url
Blog Articleslug, title, description, small_description, meta_title, meta_keywords, meta_description, url, redirect_url, builder_block_id
Badgebadge_text
Subcontentname, fulltext

Implementation Layers ​

The MUI pattern is implemented in two parallel stacks that share the same database tables:

                    +-----------------------+
                    |    Database Tables     |
                    |  master + _mui tables  |
                    +-----------+-----------+
                                |
              +-----------------+------------------+
              |                                    |
   Legacy HMVC Layer                    Modern Domain + REST Layer
   (ecommercen/)                        (src/)
              |                                    |
   Adv_base_model                       BaseRepository
   updateOrInsertMui()                  + MuiRepository
   masterWithDetails()                  + MuiWriteRepository
              |                         + MuiWriteData
   Legacy Models                        + MuiEntity
   (per-entity)                         + WriteService
              |                                    |
   Legacy Controllers                   REST Controllers
   (admin CRUD views)                   (JSON API)

Legacy Layer (HMVC) ​

Base Model Methods ​

Adv_base_model (ecommercen/core/models/Adv_base_model.php) provides two methods used by all legacy MUI models:

updateOrInsertMui($table, $masterField, $masterValue, $lang, $data) -- Upsert pattern for a single language row. Checks if a row exists for the given master ID + language; updates if found, inserts if not. Used during updates to handle languages being added after initial creation.

masterWithDetails($master, $details) -- Merges a master record with its MUI rows into a single object with a captions property keyed by language abbreviation. Used when loading records for admin editing forms.

Legacy CRUD Lifecycle ​

Create:

php
// In model (e.g. Adv_categories_model)
function add_record($data, $data_mui) {
    $this->db->insert($this->table, $data);
    $id = $this->db->insert_id();
    foreach ($data_mui as $lang => $q) {
        $q['category_id'] = $id;
        $this->db->insert($this->tableMui, $q);
    }
    return $id;
}

Update:

php
function update_record($data, $data_mui, $id) {
    $this->db->where('id', $id)->update($this->table, $data);
    foreach ($data_mui as $lang => $q) {
        $q['lang'] = $lang;
        $this->updateOrInsertMui($this->tableMui, 'category_id', $id, $lang, $q);
    }
}

Read (admin edit form):

php
function getAdminRecord($id) {
    $master = $this->db->from($this->table)->where('id', $id)->get()->row();
    $muiRecs = $this->db->from($this->tableMui)->where('badge_id', $id)->get()->result();
    foreach ($muiRecs as $row) {
        $master->{$row->lang} = $row;   // Keyed by language on master object
    }
    return $master;
}

Read (storefront list):

php
// JOIN to _mui with current language filter
$this->db->select("{$this->table}.*, {$this->tableMui}.badge_text")
    ->join($this->tableMui, "{$this->table}.id = {$this->tableMui}.badge_id")
    ->where("{$this->tableMui}.lang", $this->languageAbbr);

Delete:

php
function deleteRecord($id) {
    $this->db->delete($this->table, ['id' => $id]);
    $this->db->delete($this->tableMui, ['badge_id' => $id]);
}

Language Configuration ​

Languages are configured in application/config/languages.php:

Config KeyPurposeExample
language_abbrCurrent request language'el'
lang_uri_abbrAll available storefront languages['el' => 'greek', 'en' => 'english']
lang_descDisplay labels for storefront['el' => 'EL', 'en' => 'EN']
admin_languagesLanguages available in admin panel['el' => 'EL', 'en' => 'EN']

Helper functions:

  • get_languages() -- returns lang_desc (storefront languages)
  • getAdminLanguages() -- returns admin_languages (admin panel languages)
  • config_item('lang_uri_abbr') -- used by the modern layer's HasLocales trait

Modern Domain Layer ​

File Structure Per Entity ​

Each MUI-enabled domain entity produces these files (using Badge as example):

src/Domains/Product/Badge/
  Repository/
    Entity.php                    # Master entity
    Repository.php                # Master read repository
    RepositoryConfigurator.php    # Declares 'translations' relation
    MuiEntity.php                 # Translation entity
    MuiRepository.php             # Translation read repository
    WriteRepository.php           # Master write repository
    MuiWriteRepository.php        # Translation write repository (extends BaseMuiWriteRepository)
  Service.php                     # Read service
  WriteService.php                # Write service (CRUD with MUI)
  WriteData.php                   # Master field DTO
  MuiWriteData.php                # Translation field DTO (uses TracksPresentColumns)
  Validator.php                   # Validation for master + MUI
  ListRequest.php                 # Filter/sort definitions

Shared support classes used by every entity (src/Domains/Support/):

FilePurpose
Repository/BaseMuiWriteRepository.phpAbstract base for every MuiWriteRepository: insertForEntity(), upsertForEntity(), deleteForEntity()
Data/TracksPresentColumns.phpTrait for MuiWriteData: remembers which columns the request sent (toPresentArray())
Repository/Specification/FilterByTranslation.phpShared translation-filter subquery specification
Repository/QueryFailedException.php, Repository/SqlRedactor.phpTyped failed-read exception (SQL literals redacted) thrown by BaseRepository

Entity ​

The master entity implements FilterTranslation and uses the FiltersTranslation trait to allow extracting a specific language's translation at runtime:

php
class Entity extends BaseEntity implements FilterTranslation
{
    use FiltersTranslation;
    public ?string $repository = Repository::class;
}

The translation() method searches the loaded translations relation by language code:

php
// Get the Greek translation for a product
$greekTranslation = $product->translation('el');
// Returns the MuiEntity for lang='el', or null

MuiEntity ​

A simple BaseEntity subclass mapping the _mui table columns:

php
/**
 * @property int $id
 * @property int $badge_id
 * @property string $badge_text
 * @property string $lang
 */
class MuiEntity extends BaseEntity
{
    public ?string $repository = MuiRepository::class;
}

MuiRepository (Read) ​

Extends BaseRepository pointing at the _mui table. Has its own RelationConfigurator -- usually NullRelationConfigurator (no sub-relations), but some entities like Cms\Page have MUI-level relations (e.g. builder):

php
class MuiRepository extends BaseRepository
{
    protected string $table = 'shop_product_badges_mui';
    protected string $entity = MuiEntity::class;

    public function __construct(
        RelationConfigurator $configurator,
        ?CI_DB_query_builder $db = null,
    ) {
        parent::__construct($configurator, $db);
    }
}

The $db = null default triggers the di()->get(CI_DB_query_builder::class) fallback inside BaseRepository::__construct() (src/Domains/Support/Repository/BaseRepository.php:24-31, fallback at :28), so subclasses that only declare RelationConfigurator continue to work unchanged -- the change is fully backward-compatible.

RepositoryConfigurator (Relation Wiring) ​

The master entity's configurator declares the translations relation as ONE_TO_MANY pointing to the MuiRepository:

php
class RepositoryConfigurator implements RelationConfigurator
{
    public function getRelations(): array
    {
        return [
            'translations' => new Relation(
                Relation::ONE_TO_MANY,
                MuiRepository::class,
                'badge_id',             // FK column in the _mui table
                scopableColumn: 'lang'
            ),
        ];
    }
}

This enables ?with=translations (all locales) and ?with=translations[el] (scoped to one locale) on REST API calls, and $repository->get($id, ['translations']) in code. See Per-Relation Language Scoping for the full URL grammar and data-flow details. The scopableColumn: 'lang' named argument opts this relation into locale scoping; relations without it are never filtered regardless of request params.

MuiWriteData (DTO) ​

Immutable value object for translation input. Accepts both snake_case (DB columns) and camelCase (API) field names. Annotated with OpenAPI for API documentation:

php
class MuiWriteData
{
    use TracksPresentColumns;

    public function __construct(
        public readonly string $lang,
        public readonly ?string $badgeText = null
    ) {}

    public static function fromArray(array $data): self { /* dual-format parsing, ends with ->markPresentColumns($data) */ }
    protected static function columnAliases(): array { /* column => accepted input keys */ }
    public function toArray(bool $excludeNull = false): array { /* snake_case output */ }
}

TracksPresentColumns (src/Domains/Support/Data/TracksPresentColumns.php) records which DB columns the request supplied under any accepted alias: markPresentColumns() (:27) is called at the end of fromArray(), and toPresentArray() (:46) returns lang plus only those columns. columnAliases() is a mandatory abstract static method (:23); see src/Domains/Product/Badge/MuiWriteData.php:16-56 (trait use :19, fromArray() :27-33, columnAliases() :35). The update flow uses toPresentArray() so an omitted column is never written.

Category B field handling (null → ''): Some _mui columns are NOT NULL with no DEFAULT value and no required validation — for example, url, image, and descr on slide_mui, or name and fulltext on categories_mui (Cms\Page). When the API consumer omits these fields, the constructor sets them to null. Because BaseWriteRepository::insert() now strips null values (see below), omitting a Category B column would cause a MySQL error. To prevent this, toArray() in the affected MuiWriteData files converts null → '' for these columns:

php
// src/Domains/Slider/Slide/MuiWriteData.php (representative example)
'url'   => $this->url   ?? '',
'image' => $this->image ?? '',
'descr' => $this->descr ?? '',

This matches the legacy admin panel's behavior, where $this->input->post() always returned '' for empty form fields. The nine affected DTOs and their Category B fields are:

FileFields
src/Domains/Slider/Slide/MuiWriteData.phpurl, image, descr
src/Domains/Cms/Page/MuiWriteData.phpname, fulltext
src/Domains/Cms/Document/MuiWriteData.phpfile
src/Domains/Cms/Subcontent/MuiWriteData.phpname, fulltext
src/Domains/Map/Location/MuiWriteData.phptitle
src/Domains/Map/Map/MuiWriteData.phptitle
src/Domains/Product/ProductList/MuiWriteData.phpdescription
src/Domains/Product/Line/MuiWriteData.phpdescription
src/Domains/Product/Promo/MuiWriteData.phpdescription

MuiWriteRepository (Write) ​

Every entity's MuiWriteRepository extends the abstract Advisable\Domains\Support\Repository\BaseMuiWriteRepository (which extends BaseWriteRepository) and declares only $table, $primaryKey and $foreignKey (e.g. src/Domains/Product/Badge/Repository/MuiWriteRepository.php:7-12). The three standard methods live in the base class (src/Domains/Support/Repository/BaseMuiWriteRepository.php):

MethodPurposeStrategy
insertForEntity(int|string $entityId, array $translations) (:25)Create translations for a new master recordLoop + $this->insert() with FK (null-filtered)
upsertForEntity(int|string $entityId, array $translations, array $insertRows = []): void (:48)Update translations for an existing master recordPer sent language: UPDATE in place or INSERT (see below)
deleteForEntity(int|string $entityId) (:83)Remove all translations when master is deletedDELETE WHERE fk = id

insertForEntity() delegates to $this->insert() (inherited from BaseWriteRepository) rather than calling $this->db->insert() directly. This means every MUI row insert goes through the null-filtering step in BaseWriteRepository::insert() (see step 6 of the Create flow below).

upsertForEntity() contract (BaseMuiWriteRepository.php: docblock :33-47, signature :48, body :49-78; the former replaceForEntity() delete-all + re-insert is removed in all 38 domains; see docs/decisions/857-mui-upsert-in-place.md):

  • For each sent language it SELECTs by (foreign key, lang) (translationExists(), :119).
  • Existing row: UPDATE only the sent columns in place (:62-76), keeping the row id. If only lang was sent there are no columns to write and no UPDATE is issued (:65-67).
  • Missing row: INSERT the $insertRows full row for that language merged with the sent values, sent values winning (:56-58).
  • Languages not sent are left untouched; an update therefore cannot remove a language. Removal happens only through deleteForEntity() when the master is deleted.
  • Duplicate lang entries in the payload are merged in payload order, later wins (mergeByLang(), :93-108).
  • The SELECT-then-INSERT is not atomic; a UNIQUE(fk, lang) index is tracked by #698 (class docblock :10-14).

WriteService (CRUD Orchestration) ​

The WriteService orchestrates master and MUI operations within a database transaction:

Create flow:

1. Parse master fields -> WriteData::fromArray()
2. Validate master fields -> Validator::validateForCreate()
3. Parse translations -> MuiWriteData::fromArray() per language
4. Validate each translation -> Validator::validateTranslations()
5. BEGIN TRANSACTION
6.   INSERT master row -> WriteRepository::insert()
       BaseWriteRepository::insert() strips null values via array_filter()
       before the DB call; MySQL applies column DEFAULTs for omitted columns.
       -> returns $id
7.   INSERT MUI rows -> MuiWriteRepository::insertForEntity($id, $translations)
       Each translation row also goes through BaseWriteRepository::insert(),
       inheriting the same null filtering. Category B fields that are NOT NULL
       with no DEFAULT are coerced to '' in MuiWriteData::toArray() before
       this point (see MuiWriteData section above).
8.   Reload entity with translations -> Repository::get($id, ['translations'])
9. COMMIT
10. Return complete entity

Update flow:

1. Parse master fields -> WriteData::fromArray()
2. Validate master fields -> Validator::validateForUpdate()
3. Parse translations -> parseMuiData($data, presentOnly: true)
     (MuiWriteData::fromArray() per language; rows carry only the columns the
     request sent via toPresentArray(); null when the key is absent)
   Parse full insert rows -> parseMuiInsertRows($data) (full toArray() rows)
4. Validate each translation -> Validator::validateTranslations()
5. BEGIN TRANSACTION
6.   UPDATE master row (non-null fields only) -> WriteRepository::update()
7.   UPSERT MUI rows -> MuiWriteRepository::upsertForEntity($id, $translations, $insertRows)
8.   Reload entity with translations -> Repository::get($id, ['translations'])
9. COMMIT
10. Return complete entity

Steps 3 and 7 are src/Domains/Product/Badge/WriteService.php:42-53. On any Throwable inside the transaction, BaseWriteRepository::transactional() calls trans_rollback() and rethrows (src/Domains/Support/Repository/BaseWriteRepository.php:43-61, catch at :49-55).

Delete flow:

1. BEGIN TRANSACTION
2.   DELETE MUI rows first -> MuiWriteRepository::deleteForEntity($id)
3.   DELETE master row -> WriteRepository::delete($id)
4. COMMIT

Key detail: on update, an absent translations key and translations: [] are both no-ops; parseMuiData() still returns null for an absent key (WriteService.php:76-78) and an empty array upserts nothing. A present key with entries means a per-language upsert, not a replace. This allows updating only master fields without affecting translations.

Validator ​

Each entity's Validator has a validateTranslations() method that checks the MUI-specific rules. At minimum, lang is required on every translation:

php
public function validateTranslations(array $translations): void
{
    foreach ($translations as $i => $translation) {
        if (empty($translation->lang)) {
            $errors["translations.$i.lang"] = 'Language is required for each translation.';
        }
    }
}

Entities with slugs or names may add additional required-field checks.


REST API Layer ​

Resources ​

Each MUI entity has a MuiResource and MuiCollection pair that transforms DB rows to camelCase JSON:

php
// MuiResource -- transforms one translation row
class MuiResource extends BaseResource {
    protected function resource(): array {
        return [
            'id' => $this->resource->id,
            'badgeId' => $this->resource->badge_id,
            'badgeText' => $this->resource->badge_text ?? '',
            'lang' => $this->resource->lang ?? 'en',
        ];
    }
}

// MuiCollection -- wraps an array of MuiResource
class MuiCollection extends BaseCollection {
    public string $collects = MuiResource::class;
}

Master Resource Integration ​

The master Resource includes translations via addCollectionToData():

php
class Resource extends BaseResource {
    protected function resource(): array {
        return $this->addRelationToData([
            'id' => $this->resource->id,
            'name' => $this->resource->name,
        ]);
    }

    protected function addRelationToData(array $data): array {
        return $this->addCollectionToData($data, 'translations', MuiCollection::class);
    }
}

Translations are included in the response only when the relation is loaded (via ?with=translations).

API Request/Response Format ​

Read (GET with translations):

GET /rest/product/badge/1?with=translations

Response:
{
  "success": true,
  "data": {
    "id": 1,
    "name": "New Product",
    "badge": "/files/badges/new.png",
    "translations": [
      {"id": 10, "badgeId": 1, "badgeText": "Νέο Προϊόν", "lang": "el"},
      {"id": 11, "badgeId": 1, "badgeText": "New Product", "lang": "en"}
    ]
  }
}

Create (POST with translations):

POST /rest/product/badge
Content-Type: application/json

{
  "name": "Sale",
  "badge": "sale.png",
  "translations": [
    {"lang": "el", "badgeText": "Εκπτωση"},
    {"lang": "en", "badgeText": "Sale"}
  ]
}

Update (POST with translations):

POST /rest/product/badge/1
Content-Type: application/json

{
  "name": "Updated Name",
  "translations": [
    {"lang": "el", "badgeText": "Updated Greek"},
    {"lang": "en", "badgeText": "Updated English"}
  ]
}

Note: Omitting "translations" from the update payload leaves existing translations untouched. Including it upserts each sent language in place: the row keeps its id and only the sent fields change (an explicit null is written), a language not sent is kept, a new language is added as one row, "translations": [] changes nothing, and an update cannot remove a language.

Per-Relation Language Scoping ​

A REST caller can request only a subset of locale rows by appending bracket-enclosed locale codes to a relation name. The feature is opt-in at the RepositoryConfigurator level via scopableColumn: 'lang'; relations that do not declare this field are never filtered.

URL grammar (src/Domains/Support/Request/WithParser.php):

URL parameterEffect
?with=translationsLoad all locales (unchanged behavior)
?with=translations[el]Load Greek only
?with=translations[el,en]Load Greek and English (CSV inside brackets)
?with=translations[el],parentScoped translations + unscoped parent (, outside brackets is the relation separator)
?with=children.translations[el]Nested relation; leaf is scoped; relationParams key is the full dot-path children.translations

Opt-in declaration (src/Domains/Support/Repository/Relation.php):

php
public ?string $scopableColumn;

Each RepositoryConfigurator that participates declares scopableColumn: 'lang' on the Relation constructor call (see RepositoryConfigurator (Relation Wiring) above). All 38 translation-bearing configurators follow this pattern.

Parser: WithParser::parse(string $with): array is a static helper. It returns:

php
[
    'relations'      => ['translations' => [], 'parent' => [], ...],
    'relationParams' => ['translations' => ['el'], 'children.translations' => ['el']],
]

The bracket-aware top-level splitter treats , inside [...] as a value separator and , outside as a relation separator.

Data flow through the stack:

  1. URL parsed by WithParser::parse(), called from GenerateListRequest::generateRelationParams() (src/Domains/Support/Request/QueryListBuilder/GenerateListRequest.php)
  2. ListRequest::$relationParams carries the resulting map (src/Domains/Support/Request/QueryListBuilder/ListRequest.php)
  3. HandlesRestfulActions::show() passes $listRequest->relationParams as the 4th argument to Service::get() (src/Rest/Support/Controllers/HandlesRestfulActions.php)
  4. Service::get() forwards it to BaseRepository::get(), which calls loadRelations($resultAsArray, $relations, $relationSorts, '', $relationParams) (src/Domains/Support/Repository/BaseRepository.php)
  5. BaseRepository::loadRelations() extracts $params = $relationParams[$relationPath] ?? [] and forwards to loadRelation() and then to the loader
  6. AbstractRelationLoader::applyScopableParams() (src/Domains/Support/Repository/RelationLoader/AbstractRelationLoader.php): when $params is non-empty and $relation->scopableColumn is set, emits WHERE {table}.{scopableColumn} IN (...) on the related repository's DB builder
  7. The collection in the response contains only the scoped rows; the array shape is unchanged (still an array even for a single locale)

For index() and item() endpoints, HandlesRestfulActions::index() uses $listRequest (which already carries relationParams) → Service::all() → buildSpecifications() → new WithRelations($relations, $listRequest->getRelationSorts(), $listRequest->relationParams) — the same scoping applies.

For internal callers (jobs, services, legacy bridges) pass $relationParams directly:

php
// Repository::get()
$repo->get($id, ['translations'], [], ['translations' => ['el']]);

// Repository::loadRelations()
$repo->loadRelations($items, ['translations'], [], '', ['translations' => ['el']]);

// WithRelations specification
new WithRelations(['translations' => []], [], ['translations' => ['el']]);

Backward compatibility: an empty $relationParams = [] (the default for all existing callers) produces no IN (...) filter, so all locales are returned — identical behavior to before the feature was introduced.

OpenAPI: all 38 translation-bearing controllers' x-relations entries carry 'scopableColumn' => 'lang'. The canonical documentation is in the central OA\Info ## Relations block in src/Rest/OpenApi.php.

Filtering and Sorting by Translation Fields ​

The ListRequest class registers per-locale filter and sort entries for MUI fields using the HasLocales trait:

php
// In ListRequest::setAllowedFilters()
foreach ($this->getLocales() as $locale) {
    $this->allowedFilters["name.$locale"] = [
        'relation' => 'translations',
        'field' => 'shop_product_mui.name',
        'type' => FilterRequestType::Partial,
        'language' => $locale,
    ];
}

API usage: GET /rest/product?filter[name.el]=Προϊόν&sort=name.el

Sort by translation: Uses a SortByTranslation specification that LEFT JOINs the _mui table filtered by locale, then orders by the translated field:

php
class SortByTranslation implements Specification {
    public function apply(CI_DB_query_builder $builder) {
        $builder->select("{$table}.*");
        $builder->join("{$muiTable} AS {$alias}", "{$alias}.{$fk} = {$table}.id AND {$alias}.lang = '{$locale}'", 'left');
        $builder->order_by("{$alias}.{$field}", $this->direction);
        $builder->group_by("{$table}.id");
    }
}

When a REST client sends ?sort=name.el, GenerateListRequest::parseRelationSort() (src/Domains/Support/Request/QueryListBuilder/GenerateListRequest.php) recognises name.el as a root translation sort (it exists in allowedSorts with relation => 'translations'). It extracts the locale from the trailing key segment and stores it on SortRequest::$language (src/Domains/Support/Request/QueryListBuilder/SortRequest.php). In the domain Service's getRootSorts() loop the relation === 'translations' check routes the sort to SortByTranslation, passing the column (trailing segment of the qualified field, e.g. name from shop_product_category_mui.name) and $sort->language as the locale. Every domain that supports translation sorts must implement this relation === 'translations' branch — domains that fall through to a bare Sort will fail with SQL 1054 or return empty results because the _mui table is not in the FROM clause.

Filter by translation: Every translations filter goes through the shared Advisable\Domains\Support\Repository\Specification\FilterByTranslation (src/Domains/Support/Repository/Specification/FilterByTranslation.php), a subquery specification:

php
// Generates: WHERE shop_product.id IN (SELECT product_id FROM shop_product_mui WHERE lang = 'el' AND name LIKE '%term%')
  • Constructor (:36-45): masterKey, translationTable, foreignKey, field, values, locale, type, localeColumn = 'lang'.
  • Supports only Exact (IN) and Partial (LIKE per value, OR-ed, %/_ matched literally); any other type throws \LogicException (:52-58). A null locale matches any locale (:67).
  • Built by BuildsFilterSpecifications::translationFilterSpecification() (src/Domains/Support/Service/BuildsFilterSpecifications.php:163, routed from :143-144) from the repository's own translations relation (table, foreign key, scopableColumn) and the master column returned by BaseRepository::relationLocalKey() (src/Domains/Support/Repository/BaseRepository.php:305). Product\Variation\Repository\Repository overrides it to return group_id for translations (src/Domains/Product/Variation/Repository/Repository.php:25-28).
  • A filter the database rejects surfaces as a QueryFailedException (BaseRepository::guardedRead(), BaseRepository.php:84-141, docblock :84-96, QueryFailedException thrown at :129-140), logged by BaseRepository::logQueryFailure() (:146); the exception and SqlRedactor live in src/Domains/Support/Repository/ and literal SQL values are redacted to ? in the log.
  • The 19 per-domain FilterByTranslation classes are kept and still used by their domains (e.g. src/Domains/Product/Category/Service.php:90).

DI Container Registration ​

MUI components are registered in each domain's container.php. The pattern differs based on whether the MuiRepository has its own relations:

Without MUI-level relations (most entities):

php
$services->set(Badge\Repository\MuiRepository::class)
    ->arg('$configurator', new Reference(NullRelationConfigurator::class));
$services->set(Badge\Repository\MuiWriteRepository::class);

With MUI-level relations (e.g. Product, Page):

php
$services->set(Product\Repository\MuiRepositoryConfigurator::class);
$services->set(Product\Repository\MuiRepository::class)
    ->arg('$configurator', new Reference(Product\Repository\MuiRepositoryConfigurator::class));
$services->set(Product\Repository\MuiWriteRepository::class);

Slug and URL Handling ​

Entities with public-facing URLs (products, categories, blog articles, pages, events, offers, videos) store slug and optionally url and redirect_url in the _mui table. This means each language can have its own URL-friendly slug.

Slug generation is handled by the url_title() helper (application/helpers/MY_url_helper.php), which extends CI's default with full Greek character support -- converting accented Greek characters to their base forms, lowercasing via mb_strtolower, and replacing spaces with hyphens.

Slug generation typically happens in the admin frontend (Vue components or form handlers) rather than in the backend model layer. The backend stores whatever slug value is submitted.


Complete Entity Inventory ​

All 38 entities currently using the MUI pattern:

ContextEntityMUI TableNotable MUI Fields
AiPositionai_positions_muitext fields
CmsBlog Articleblog_muislug, title, description, SEO
CmsBlog Authorblog_author_muiname, slug, SEO
CmsBlog Categoryblog_category_muiname, slug, SEO
CmsBlog Tagblog_tags_muiname, slug, SEO
CmsDocumentdocuments_muiname, slug
CmsOfferoffers_muiname, slug, description, SEO
CmsOffer Categoryoffers_category_muiname, slug, SEO
CmsPagecategories_muiname, slug, fulltext, SEO
CmsSubcontentcms_subcontent_muiname, fulltext
CmsVideovideo_muiname, slug, description, SEO
CountryCountrycountry_muiname
CountryCountycounty_muiname
EventCategoryevent_categories_muiname, slug, description, SEO
EventEventevents_muiname, slug, description, SEO
MapLocationmaps_locations_muiname, description, address
MapMapmaps_muiname, description
OrderStorestores_muiname, address
ProductAttributeshop_product_attribute_values_muiname
ProductAttribute Groupshop_product_attribute_groups_muiname
ProductBadgeshop_product_badges_muibadge_text
ProductCategoryshop_product_category_muiname, slug, fulltext, SEO
ProductLineshop_product_lines_muiname, slug, SEO
ProductProductshop_product_muiname, slug, description, SEO, usage, ingredients
ProductProduct Listshop_product_lists_muiname, slug, description, SEO
ProductPromoshop_product_promo_muiname, slug, description, SEO
ProductRelated Groupshop_product_related_groups_muiname
ProductSuppliershop_product_supplier_muiname, slug
ProductTagshop_product_tags_muiname, slug
ProductTag Categoryshop_product_tag_categories_muiname, slug
ProductVendorshop_vendor_muiname, vendor_slug, SEO
ProductVariationproduct_variations_muiname (the variation group's name, keyed by group_id)
ProductVariation Groupvariation_groups_muiname
ProductVariation Valuevariation_values_muiname
PromotionGiftshop_gift_rules_muititle, description, SEO
SliderSlideslide_muititle, description, link
SliderSlidersliders_group_muiname
TransporterTransportershop_transporters_muiname

Tables: database/initial/initial.sql:964 (product_variations_mui), :2366 (variation_groups_mui), :2385 (variation_values_mui); each entity's $table is at :9 of its MuiWriteRepository.php. Variation translations are keyed by the variation group (foreignKey = 'group_id', src/Domains/Product/Variation/Repository/MuiWriteRepository.php:12), so they are shared by every variation in that group; DELETE of a variation does not touch them (src/Domains/Product/Variation/WriteService.php:68-73) and the group id is resolved by resolveGroupId() (:80-85, used in create()/update() at :31, :56-62).


Comparison: Legacy vs. Modern ​

AspectLegacy (HMVC)Modern (Domain/REST)
MUI save strategy (update)updateOrInsertMui() per language (upsert)upsertForEntity() per language (update-in-place or insert, same semantics as legacy updateOrInsertMui() at ecommercen/core/models/Adv_base_model.php:42-52)
MUI save strategy (create)Loop INSERT per languageinsertForEntity() loop INSERT
Transaction handlingNo explicit transactionstransactional() wrapper; rolls back and rethrows on Throwable (BaseWriteRepository.php:43-61)
MUI data structure on read$master->{$lang} = $row (keyed by lang)$entity->translations[] array of MuiEntity
Filtering by languageJOIN + WHERE langSubquery or JOIN via Specification
Input format$_POST form data keyed by languageJSON translations[] array
ValidationCI form_validationDedicated Validator class
Slug generationFrontend / url_title() helperFrontend / API consumer

Known Issues & Security Gaps ​

  • fromArray() duplicate-key lookups in 7 MuiWriteData files — The snake_case fallback to camelCase in fromArray() is silently broken in 7 files: both sides of the ?? operator use the same array key (e.g. $data['url'] ?? $data['url'] ?? null), meaning the camelCase variant never fires. Affected: src/Domains/Slider/Slide/MuiWriteData.php:49-58, src/Domains/Map/Location/MuiWriteData.php:39-41, src/Domains/Map/Map/MuiWriteData.php:33-34, src/Domains/Product/ProductList/MuiWriteData.php:33-34, src/Domains/Product/Line/MuiWriteData.php:44-46, src/Domains/Product/Promo/MuiWriteData.php:45-49, src/Domains/Cms/Document/MuiWriteData.php:33-34. These fields only accept snake_case input from the API despite the dual-format design intent.

References ​

  • Base Model: ecommercen/core/models/Adv_base_model.php -- updateOrInsertMui(), masterWithDetails()
  • Support Classes: src/Domains/Support/Repository/BaseRepository.php, BaseWriteRepository.php, BaseMuiWriteRepository.php -- upsertForEntity()
  • Present-column tracking: src/Domains/Support/Data/TracksPresentColumns.php -- markPresentColumns(), toPresentArray()
  • Failed-read handling: src/Domains/Support/Repository/QueryFailedException.php, SqlRedactor.php
  • Shared translation filter: src/Domains/Support/Repository/Specification/FilterByTranslation.php, built by src/Domains/Support/Service/BuildsFilterSpecifications.php -- translationFilterSpecification()
  • Relation System: src/Domains/Support/Repository/Relation.php, RelationConfigurator.php
  • With/Scoping Parser: src/Domains/Support/Request/WithParser.php -- parse() static helper, bracket-aware grammar
  • REST Relation Helpers: src/Domains/Support/Request/GetsRequestRelations.php -- trait that wires WithParser into REST controllers
  • Translation Filtering: src/Domains/Support/Model/FilterTranslation.php, FiltersTranslation.php
  • Specification Factories: src/Domains/Support/Repository/Specification/NotEmptySpecificationFactory.php
  • REST Support: src/Rest/Support/Resources/BaseResource.php -- addCollectionToData()
  • Language Config: application/config/languages.php
  • Language Helpers: application/helpers/MY_language_helper.php
  • Slug Helper: application/helpers/MY_url_helper.php -- url_title() with Greek support
  • Container Pattern: src/Domains/Product/container.php (reference for MUI DI wiring)