{"record":{"id":"d7f4034d08555815","repo":"octobercms/october","slug":"media-tags-can-only-be-processed-for-front-end-req","errorCode":null,"errorMessage":"Media tags can only be processed for front-end requests.","messagePattern":"Media tags can only be processed for front-end requests\\.","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"modules/media/helpers/MediaView.php","lineNumber":102,"sourceCode":"        if ($this->playerPartialExists($partialName)) {\n            return Controller::getController()->renderPartial($partialName, ['src' => $src]);\n        }\n\n        return $this->getDefaultPlayerMarkup($type, $src);\n    }\n\n    /**\n     * playerPartialExists\n     */\n    protected function playerPartialExists($name)\n    {\n        if (array_key_exists($name, $this->playerPartialFlags)) {\n            return $this->playerPartialFlags[$name];\n        }\n\n        $controller = Controller::getController();\n        if (!$controller) {\n            throw new ApplicationException('Media tags can only be processed for front-end requests.');\n        }\n\n        $partial = Partial::loadCached($controller->getTheme(), $name);\n\n        return $this->playerPartialFlags[$name] = !!$partial;\n    }\n\n    /**\n     * getDefaultPlayerMarkup\n     */\n    protected function getDefaultPlayerMarkup($type, $src)\n    {\n        switch ($type) {\n            case 'video':\n                return '<video src=\"'.e($src).'\" controls preload=\"metadata\"></video>';\n            break;\n\n            case 'audio':","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/media/helpers/MediaView.php#L84-L120","documentation":"MediaView is the front-end markup extension that replaces data-audio/data-video figure tags inserted by the Media Manager with player partials. playerPartialExists() needs the active CMS controller to resolve the theme partial (Partial::loadCached($controller->getTheme(), $name)); when Controller::getController() returns null the exception 'Media tags can only be processed for front-end requests.' is thrown. A null controller occurs whenever processHtml() runs outside an HTTP front-end request: CLI/artisan, queue workers, scheduled tasks, unit tests, or after the controller was reset mid-process.","triggerScenarios":"Calling MediaView::instance()->processHtml($html) from a queue job or artisan command (e.g. rendering page HTML for a sitemap, PDF export, or search indexer); a PHPUnit test exercising media-tag markup without a CMS controller booted; mail/preview generation containing data-audio/data-video tags.","commonSituations":"Background generators that reuse front-end filters; plugin tests rendering theme content; content migrations that run tag processing in console context.","solutions":["Gate tag processing on an actual front-end controller: only call processHtml() when \\Cms\\Classes\\Controller::getController() is non-null and not running in console","For tests, boot a CMS controller first (or mock Controller::getController()) so partial resolution has a theme context","In queue workers, generate the markup on the front-end request and persist the result, instead of re-processing raw HTML in the job"],"exampleFix":"// before — runs in a queue job / artisan command\n$html = \\Media\\Helpers\\MediaView::instance()->processHtml($page->markup);\n\n// after — only process when a front-end controller exists\nif (\\Cms\\Classes\\Controller::getController() && !app()->runningInConsole()) {\n    $html = \\Media\\Helpers\\MediaView::instance()->processHtml($page->markup);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"function canProcessMediaTags(): bool\n{\n    return \\Cms\\Classes\\Controller::getController() !== null\n        && !app()->runningInConsole();\n}\n\n// usage\n$html = canProcessMediaTags()\n    ? \\Media\\Helpers\\MediaView::instance()->processHtml($html)\n    : $html; // leave tags untouched outside front-end requests","tryCatchPattern":"try {\n    $html = \\Media\\Helpers\\MediaView::instance()->processHtml($html);\n} catch (ApplicationException $e) {\n    // Queue/CLI context: fall back to raw HTML rather than failing the job\n    Log::info('Skipped media tag processing: '.$e->getMessage());\n}","preventionTips":["Keep tag post-processing on the front-end request path; persist rendered output for background consumers","Boot a CMS controller (or mock getController) in tests that render theme markup","Remember data-audio/data-video figures require a theme context — avoid them in system-generated HTML"],"tags":["media","media-tags","frontend","queue","cli","context"],"backgroundTag":"no-active-controller","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}