Skip to content

MelisCmsCategory2

Multi-site, multilingual content categories for the CMS — package melisplatform/melis-cms-category2.

Purpose

MelisCmsCategory2 provides a hierarchical category system in the Melis backoffice. Categories form a tree (each node points to a parent), carry per-language translations (name and description), can be scoped to one or more sites, have a validity window and a status, and can hold media files. The module ships a front-office templating plugin to render a category tree on a page and a reusable category picker embedded by other modules (e.g. News, Commerce) to classify their records.

Enable it

Add to config/melis.module.load.php:

php
return [
    'MelisCmsCategory2',
];

Requires melis-core and melis-cms (^5.2). The module is dbdeploy-enabled so its tables are created on deploy. melis-engine is also needed for front rendering.

Key services

Service aliasRole
MelisCmsCategory2ServiceMain category service: create/read category nodes, tree retrieval, translations and site links.
MelisCmsCategory2MediaServicePer-category file storage on disk and in the database.

Notable methods on MelisCmsCategory2Service:

  • getCategoryTreeview($fatherId, $langId, $onlyValid, $siteId) — recursive tree.
  • getCategoryById($categoryId, $langId, $onlyValid) — full category node.
  • getCategoryNameById($categoryId, $langId) — name lookup.
  • getCategoryListByIdRecursive(...) — flat recursive list.
  • getCategoryTranslationById(...) — single translation row.
  • getFirstLevelCategoriesPerSite($siteId, $langId), getCategoriesPerSite($siteId, $langId).
  • getCategoryMediaById(...) — media rows for a node.
  • saveCategory(...) — create or update a node.
  • saveCategoryTexts($categoryId, $catLangId, $postData, $id) — save a translation row.
  • saveCategorySites($categoryId, $siteId, $id, $toDelete) — link or unlink a site.
  • reOrderCategories($parentId, $currentOrder) — persist drag-reorder.
  • validateDates($dateStart, $dateEnd).

MelisCmsCategory2MediaService handles the filesystem side: uploadFile, deleteFile, getMediaFilesByCategoryId, getFilesInDir, removeCategoryDir.

Backoffice

The Category manager is accessible from the CMS tools section of the backoffice left menu (fa-th-list icon). It shows catalogs as an accordion, each holding its jsTree of categories, with a search box and a site filter. Controllers:

ControllerUsed for
MelisCmsCategoryListControllerCategory list, tree view, site filter, search, add catalog/category.
MelisCmsCategoryControllerThe category edit form (translations, status, validity dates, sites).
MelisCmsCategoryMediaControllerThe Media tab — browse, upload, delete category media.
MelisCmsCategorySelectControllerThe "select a category" picker modal, reused by other modules.

The MelisCmsCategorySelect form element (factory MelisCmsCategorySelectFactory) lets any module embed a category picker in its own forms.

Front office

  • Templating plugin MelisCmsCategoryDisplayCategoriesPlugin — renders a category tree on a page. Configuration (config/plugins/MelisCmsCategoryDisplayCategoriesPlugin.config.php) exposes one Properties tab with three fields: template_path, site_id, category_start. Default template: MelisCmsCategory2/default (view/.../plugins/default.phtml).
  • View helper renderTreeRec — recursively renders a category tree array inside a view.

Hardcoded usage:

php
$display = $this->MelisCmsCategoryDisplayCategoriesPlugin();
echo $display->render([
    'template_path' => ['MelisCmsCategory2/default'],
    'site_id'        => 1,
    'category_start' => 1,
]);

Database tables

TableHolds
melis_cms_category2Category node: cat2_id, cat2_father_cat_id, order, status, reference, validity dates, audit.
melis_cms_category2_transPer-language translation: name and description, keyed by catt2_id.
melis_cms_category2_sitesCategory-to-site link, keyed by cats2_id.
melis_cms_category2_mediaMedia attached to a category: catm2_type, catm2_path, catm2_cat_id.

A seed root node (cat2_id = 1, "My catalog" / "Mon catalogue") is inserted on install.

Example

Fetch and render the category tree from any controller or service:

php
$cat = $this->getServiceManager()->get('MelisCmsCategory2Service');

// Recursive tree — valid categories only, scoped to a site
$tree = $cat->getCategoryTreeview($fatherId, $langId, true, $siteId);

// Single node with translations
$node = $cat->getCategoryById($categoryId, $langId, false);

// Name lookup
$name = $cat->getCategoryNameById($categoryId, $langId);

// All categories for a site
$site = $cat->getCategoriesPerSite($siteId, $langId);

Key files

ConcernPath
Module config (services, controllers, plugin, view helper)vendor/melisplatform/melis-cms-category2/config/module.config.php
Backoffice tools tree / interfacesvendor/melisplatform/melis-cms-category2/config/app.interface.php
Main servicevendor/melisplatform/melis-cms-category2/src/Service/MelisCmsCategoryService.php
Media servicevendor/melisplatform/melis-cms-category2/src/Service/MelisCmsCategoryMediaService.php
Category picker form element factoryvendor/melisplatform/melis-cms-category2/src/Form/Factory/MelisCmsCategorySelectFactory.php
Templating pluginvendor/melisplatform/melis-cms-category2/src/Controller/Plugin/MelisCmsCategoryDisplayCategoriesPlugin.php
Plugin configvendor/melisplatform/melis-cms-category2/config/plugins/MelisCmsCategoryDisplayCategoriesPlugin.config.php
Install SQLvendor/melisplatform/melis-cms-category2/install/sql/

See also: melis-cms, melis-core, melis-cms-news