diff options
Diffstat (limited to 'lib/public')
-rw-r--r-- | lib/public/AppFramework/Http/TemplateResponse.php | 37 |
1 files changed, 34 insertions, 3 deletions
diff --git a/lib/public/AppFramework/Http/TemplateResponse.php b/lib/public/AppFramework/Http/TemplateResponse.php index 48e6c43411f..9622d9696dc 100644 --- a/lib/public/AppFramework/Http/TemplateResponse.php +++ b/lib/public/AppFramework/Http/TemplateResponse.php @@ -39,6 +39,27 @@ namespace OCP\AppFramework\Http; */ class TemplateResponse extends Response { /** + * @since 20.0.0 + */ + public const RENDER_AS_GUEST = 'guest'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_BLANK = ''; + /** + * @since 20.0.0 + */ + public const RENDER_AS_USER = 'user'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_ERROR = 'error'; + /** + * @since 20.0.0 + */ + public const RENDER_AS_PUBLIC = 'public'; + + /** * @deprecated 20.0.0 use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent */ public const EVENT_LOAD_ADDITIONAL_SCRIPTS = self::class . '::loadAdditionalScripts'; @@ -81,7 +102,7 @@ class TemplateResponse extends Response { * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 */ public function __construct($appName, $templateName, array $params=[], - $renderAs='user') { + $renderAs = self::RENDER_AS_USER) { parent::__construct(); $this->templateName = $templateName; @@ -160,8 +181,18 @@ class TemplateResponse extends Response { * @since 6.0.0 */ public function render() { - // \OCP\Template needs an empty string instead of 'blank' for an unwrapped response - $renderAs = $this->renderAs === 'blank' ? '' : $this->renderAs; + $renderAs = self::RENDER_AS_USER; + if ($this->renderAs === 'blank') { + // Legacy fallback as \OCP\Template needs an empty string instead of 'blank' for an unwrapped response + $renderAs = self::RENDER_AS_BLANK; + } elseif (in_array($this->renderAs, [ + self::RENDER_AS_GUEST, + self::RENDER_AS_BLANK, + self::RENDER_AS_ERROR, + self::RENDER_AS_PUBLIC, + self::RENDER_AS_USER], true)) { + $renderAs = $this->renderAs; + } \OCP\Util::addHeader('meta', ['name' => 'robots', 'content' => 'noindex, nofollow']); $template = new \OCP\Template($this->appName, $this->templateName, $renderAs); |