{"record":{"id":"ce9b1f468dc0df02","repo":"octobercms/october","slug":"unknown-document-type-s","errorCode":null,"errorMessage":"Unknown document type: %s","messagePattern":"Unknown document type: (.+?)","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/cms/classes/EditorExtension.php","lineNumber":303,"sourceCode":"     * @return array\n     */\n    public function getSettingsForms()\n    {\n        return [\n            EditorExtension::DOCUMENT_TYPE_PAGE => $this->loadAndExtendCmsSettingsFields(\\Cms\\Classes\\Page\\Fields::class, 'page'),\n            EditorExtension::DOCUMENT_TYPE_PARTIAL => $this->loadAndExtendCmsSettingsFields(\\Cms\\Classes\\Partial\\Fields::class, 'partial'),\n            EditorExtension::DOCUMENT_TYPE_LAYOUT => $this->loadAndExtendCmsSettingsFields(\\Cms\\Classes\\Layout\\Fields::class, 'layout')\n        ];\n    }\n\n    /**\n     * hasAccessToDocType\n     * @return array\n     */\n    public static function hasAccessToDocType($user, $documentType)\n    {\n        if (!array_key_exists($documentType, EditorExtension::DOCUMENT_TYPE_PERMISSIONS)) {\n            throw new SystemException(sprintf('Unknown document type: %s', $documentType));\n        }\n\n        return $user->hasAnyAccess(EditorExtension::DOCUMENT_TYPE_PERMISSIONS[$documentType]);\n    }\n\n    /**\n     * getTheme returns the theme object to use for the editor\n     */\n    protected function getTheme()\n    {\n        if ($this->cachedEditTheme !== false) {\n            return $this->cachedEditTheme;\n        }\n\n        // Locate edit theme\n        try {\n            if ($editTheme = Theme::getEditTheme()) {\n                return $this->cachedEditTheme = $editTheme;","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/cms/classes/EditorExtension.php#L285-L321","documentation":"SystemException thrown by `EditorExtension::hasAccessToDocType($user, $documentType)` when the given document type string is not a key of `DOCUMENT_TYPE_PERMISSIONS`. Valid keys are the constants cms-page, cms-partial, cms-layout, cms-content, cms-asset, cms-lang. This is a programmer/API-contract guard: the editor permission layer refuses unknown document types before any permission lookup.","triggerScenarios":"Calling `EditorExtension::hasAccessToDocType($user, 'cms-pagee')` (typo), a custom plugin passing its own document type string ('myplugin-doc') into the CMS editor extension, or forwarding an unvalidated `documentType` request parameter from an AJAX handler into this API.","commonSituations":"Plugin developers extending the CMS editor with new document types without registering them in the permissions map; refactors that rename a constant but leave stale string literals; unvalidated user input reaching an editor permission check.","solutions":["Use the `EditorExtension::DOCUMENT_TYPE_*` constants instead of raw strings when calling hasAccessToDocType.","If you need a custom document type, extend/patch DOCUMENT_TYPE_PERMISSIONS in your plugin so the type maps to permission codes.","Validate the value against `array_keys(EditorExtension::DOCUMENT_TYPE_PERMISSIONS)` before calling the API."],"exampleFix":"// before\nEditorExtension::hasAccessToDocType($user, 'cms-pagee'); // typo'd literal\n\n// after\nuse Cms\\Classes\\EditorExtension;\n\n$type = EditorExtension::DOCUMENT_TYPE_PAGE;\nif (array_key_exists($type, EditorExtension::DOCUMENT_TYPE_PERMISSIONS)) {\n    EditorExtension::hasAccessToDocType($user, $type);\n}","handlingStrategy":"type-guard","validationCode":"use Cms\\Classes\\EditorExtension;\n\n$valid = array_key_exists($documentType, EditorExtension::DOCUMENT_TYPE_PERMISSIONS);\nif (!$valid) {\n    abort(400, 'Unsupported document type');\n}","typeGuard":"/** @param mixed $type */\nfunction isValidDocumentType($type): bool\n{\n    return is_string($type)\n        && array_key_exists($type, \\Cms\\Classes\\EditorExtension::DOCUMENT_TYPE_PERMISSIONS);\n}","tryCatchPattern":"try {\n    $allowed = EditorExtension::hasAccessToDocType($user, $documentType);\n} catch (System\\Exception $e) {\n    // unknown type is a caller bug: log with the offending value and 400 out\n    Log::warning('Bad editor document type', ['type' => $documentType]);\n    return response()->json(['error' => 'Invalid document type'], 400);\n}","preventionTips":["Always reference the EditorExtension::DOCUMENT_TYPE_* constants instead of string literals.","Never pass a raw request parameter into permission APIs without an allow-list check.","Declare the parameter type (string) and validate against the permissions map at your API boundary.","Add unit tests covering every document type your plugin uses."],"tags":["editor","permissions","api-misuse","enum-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}