#64461·server

DirectEditing Manager::getTemplates() crashes when a creator returns ATemplate objects (per interface contract)

Author: IoSonoPieroCreated Sep 17, 2026Updated Sep 17, 2026
Labels3. to review

Steps to reproduce

  1. Server on Nextcloud 34.0.4.1 with richdocuments 11.1.1 (implements OCP\DirectEditing\ACreateFromTemplate and follows PR https://github.com/nextcloud/richdocuments/pull/5656, "integrate with OCP\DirectEditing API").
  2. From the Nextcloud Android app (v35.0.0), tap "+" → "New document" (or spreadsheet).
  3. App calls GET /ocs/v2.php/apps/files/api/v1/directEditing/templates/richdocuments/document (and /spreadsheet).

Expected behaviour

Template list is returned, template picker opens.

Actual behaviour

500 error, request fails every time, for every creator type (document, spreadsheet — both tested). Exception in nextcloud.log:

Cannot use object of type OCA\Richdocuments\DirectEditing\OfficeTemplate as array in file
'/var/www/html/lib/private/DirectEditing/Manager.php' line 91

Root cause

OCP\DirectEditing\ACreateFromTemplate::getTemplates() is documented to return ATemplate[]: https://github.com/nextcloud/server/blob/v34.0.4/lib/public/DirectEditing/ACreateFromTemplate.php

richdocuments' AbstractOfficeCreator::getTemplates() follows this literally and returns an array of OfficeTemplate objects (extending ATemplate): https://github.com/nextcloud/richdocuments/blob/v11.1.1/lib/DirectEditing/AbstractOfficeCreator.php#L67-L75

But OC\DirectEditing\Manager::getTemplates() (private) treats each element as a plain associative array, not an object:

php
$templates = array_map(function ($template) use ($creator) {
    $template['extension'] = $creator->getExtension();
    $template['mimetype'] = $creator->getMimetype();
    return $template;
}, $templates);

https://github.com/nextcloud/server/blob/v34.0.4/lib/private/DirectEditing/Manager.php#L75-L96

This array-mutation code appears unchanged since at least Nextcloud 30 (checked v30.0.0 tag, identical logic), so it silently relied on apps returning raw arrays despite the interface declaring ATemplate[] since 18.0.0. Any app that follows the documented contract literally (as richdocuments now does, after its recent OCP\DirectEditing refactor) breaks this code with a fatal error.

Fix suggestion

Manager::getTemplates() should call $template->jsonSerialize() (or equivalent) before mutating, since ATemplate implements JsonSerializable and already exposes id/title/preview via jsonSerialize(): https://github.com/nextcloud/server/blob/v34.0.4/lib/public/DirectEditing/ATemplate.php

Environment

  • Nextcloud 34.0.4.1
  • richdocuments 11.1.1
  • Nextcloud Android app 35.0.0
  • Reproduced with both document and spreadsheet creator types