Skip to content

refactor!: pass the data to the add/edit methods of the handler classes uniformly - #6781

Merged
gharlan merged 2 commits into
6.xfrom
handler-params
Oct 21, 2026
Merged

gharlan merged 2 commits into
6.xfrom
handler-params

Conversation

@gharlan

@gharlan gharlan commented Oct 21, 2026

Copy link
Copy Markdown
Member

The add/edit methods of the handler classes took their data in different ways: $data arrays with legacy keys (catname, catpriority), the parent as a separate parameter or as an object, or a list of positional values (LanguageHandler). This aligns ArticleHandler, CategoryHandler, LanguageHandler and MediaCategoryHandler:

  • the values to store are passed as one $data array, keyed like the columns, followed by $meta
  • the identity of an existing record ($id, $languageId) stays a separate parameter
  • in edit() missing keys keep their value, a given key (also null) is stored
  • priority is optional in add() and appends the element
CategoryHandler::add(['parent_id' => 5, 'name' => 'Foo']);
CategoryHandler::edit($id, $languageId, ['priority' => 2]);
LanguageHandler::edit($id, ['status' => true]);
MediaCategoryHandler::add(['parent_id' => null, 'name' => 'Foo']);

Arrays rather than single parameters, because they can get new fields after the release without breaking callers, and they distinguish a missing key from an explicit null.

Breaking changes

  • CategoryHandler::add(?int $categoryId, array $data, …) → add(array $data, …) with parent_id; catname/catpriority → name/priority; the separate start article name is gone, the start article gets the category name
  • CategoryHandler::edit(): catname/catpriority → name/priority
  • ArticleHandler::edit(): name is no longer required
  • LanguageHandler::add()/edit() take $data arrays instead of positional values
  • MediaCategoryHandler::add(string $name, ?MediaCategory $parent) → add(array $data) with parent_id; an unknown parent now throws a UserMessageException instead of silently creating a root category

Fix

MediaCategory read the root path | as [0], so getParentTree() threw for every media category and subcategories were stored with a leading 0 in their path.

MediaHandler follows in a separate PR (passing the file as a Symfony File/UploadedFile instead of the $_FILES shape).

…es uniformly

The add/edit methods of `ArticleHandler`, `CategoryHandler`, `LanguageHandler` and `MediaCategoryHandler` now all
take the values to store as one `$data` array, keyed like the columns, followed by `$meta`:

    CategoryHandler::add($parentId, ['catname' => …, 'catpriority' => …])  -> add(['parent_id' => …, 'name' => …, 'priority' => …])
    CategoryHandler::edit($id, $languageId, ['catname' => …])              -> edit($id, $languageId, ['name' => …])
    LanguageHandler::add($code, $name, $priority, $status)                 -> add(['code' => …, 'name' => …, …])
    LanguageHandler::edit($id, $code, $name, $priority, $status)           -> edit($id, ['status' => …])
    MediaCategoryHandler::add($name, $parent)                              -> add(['parent_id' => …, 'name' => …])

Arrays can grow without breaking callers and distinguish a missing key from `null`. In `edit()` missing keys keep
their value, so e.g. toggling the status of a language no longer requires passing all other values. `priority` is
optional in `add()` and appends the element. The start article of a new category always gets the category name.
`Type::requireKeys()` replaces the private `reqKey()` helpers and accepts `null` values.

Also fixes the path of media categories: the root path `|` was read as `[0]`, so `MediaCategory::getParentTree()`
failed for every category and subcategories were stored with a leading `0`.
@gharlan
gharlan merged commit e7da9f2 into 6.x Oct 21, 2026
15 checks passed
@gharlan
gharlan deleted the handler-params branch October 21, 2026 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

2 participants