Setters/Adders

addFooterData
addResource
addResponseParameter
addResponseParameters
setJSONFlags
setAllowedMethods
setBlockSize
setFileRedirect
setFileRedirectMask
setFileRedirectRelDir
setCsrfToken
addImportmapEntry

addFooterData

Adds arbitrary data to the page footer.
@param string $data Raw footer data or HTML to add
@return $this Fluent interface

addFooterData(string $data): self

addResource

Adds a JavaScript or CSS resource to the page.
@param string $source File path or inline code of the resource
@param int $type Resource type: JS or CSS (defaults to JS)
@param int $position Position where the resource should be included (head, footer, inline, etc.)
@param bool $compress Whether to compress/minify the resource (default true)
@return $this Fluent interface

addResource(string $source, int $type = self::RESOURCE_TYPE_JS, int $position = self::RESOURCE_POS_HEAD, bool $compress = true): self

$type:

ConstantDefinition
RESOURCE_TYPE_JSJavascript file
RESOURCE_TYPE_CSSCSS file

$position:

ConstantDefinition
RESOURCE_POS_HEADAdds file reference to the header
RESOURCE_POS_FOOTERAdds file reference to the footer
RESOURCE_POS_INLINEAdds inline code to the header
RESOURCE_POS_INLINE_FOOTERAdds inline code to the footer

Example:

$this->addResource('path/to/the/file', parent::RESOURCE_TYPE_CSS, parent::RESOURCE_POS_FOOTER, true);

addResponseParameter

Adds a single parameter to the response parameters array.
@param string $key Parameter key
@param mixed $value Parameter value
@return $this Fluent interface

addResponseParameter(string $key, mixed $value): self

addResponseParameters

Adds multiple parameters to the response parameters array.
@param array $parameters Associative array of parameters to add
@return $this Fluent interface

addResponseParameters(array $parameters): self

setJSONFlags

Sets JSON encoding flags for JSON responses.
@param int $flags Bitmask of JSON encoding flags
@return $this Fluent interface

setJSONFlags(int $flags): self

setAllowedMethods

Sets the allowed HTTP methods for the request.
@param array|null $allowedMethods Array of allowed methods or null to unset
@return $this Fluent interface

setAllowedMethods(?array $allowedMethods): self

setBlockSize

Sets the block size used for streaming files.
@param int|null $blockSize Block size in bytes or null to unset
@return $this Fluent interface

setBlockSize(?int $blockSize): self

setFileRedirect

Sets the file redirect method used (none, Apache, Nginx).
@param int $fileRedirect File redirect type constant
@return $this Fluent interface

setFileRedirect(int $fileRedirect): self

setFileRedirectMask

Sets the file redirect mask, used for Nginx's X-Accel-Redirect.
@param string|null $fileRedirectMask Mask path or null to unset
@return $this Fluent interface

setFileRedirectMask(?string $fileRedirectMask): self

setFileRedirectRelDir

Sets the file redirect relative directory, used for Nginx's X-Accel-Redirect.
@param string|null $fileRedirectRelDir Relative directory path or null to unset
@return $this Fluent interface

setFileRedirectRelDir(?string $fileRedirectRelDir): self

setCsrfToken

Sets the CSRF token for request protection.
@param string $csrfToken CSRF token string
@return $this Fluent interface

setCsrfToken(string $csrfToken): self

addImportmapEntry

Adds an entry to the import map.
 

@param string $key The key/specifier for the import map entry
@param string $path The file path to the asset
@param bool $isPublicResource If true, converts path to public web URL using PathUtility; if false, uses raw path
@param int $moduleSpecifierKey The import map section to use (default: self::IMPORTMAP_IMPORTS)
@return self Fluent interface for chaining
 

addImportmapEntry(string $key, string $path, bool $isPublicResource = true, int $moduleSpecifierKey = self::IMPORTMAP_IMPORTS): self

Import map module specifier keys:

ConstantDescription
IMPORTMAP_IMPORTSUses the “imports” key in the map.
IMPORTMAP_INTEGRITYUses the “integrity” key in the map.
IMPORTMAP_SCOPESUses the “scopes” key in the map.

See: Import map specification


Example:

$this->addImportmapEntry('jquery', 'EXT:extension/Resources/Public/JS/jquery.js');

Result:

<script type="importmap">
  {
    "imports": {
      "jquery": "/_assets/.../JS/jquery.js"
    }
  }
</script>