Context and parameters
Action context#
A parameter of type \TYPO3\CMS\Core\Action\ActionContext is not part of
the public schema. TYPO3 supplies it, with these properties:
$context->context- The TYPO3
Context. $context->principal- The authenticated user of the action.
$context->translator- A translator in the language of this user.
$context->request- The current request, if there is one.
$context->scopes- The scopes of the caller.
Parameter sources#
The values of route placeholders come from the path. For actions with a body
(POST, PUT, PATCH), the other parameters come from the JSON request body.
For all other actions, they come from the query. The attribute
\TYPO3\CMS\Core\Attribute\ActionParameter makes a parameter of an action
with a body a query parameter. Use this for arguments about the context of a
request, not about the submitted data, for example a workspace:
use TYPO3\CMS\Core\Action\ParameterSource;
use TYPO3\CMS\Core\Attribute\ActionParameter;
public function perform(
string $title,
#[ActionParameter(source: ParameterSource::query)]
?int $workspace = null,
): void {
// …
}use TYPO3\CMS\Core\Action\ParameterSource;
use TYPO3\CMS\Core\Attribute\ActionParameter;
public function perform(
string $title,
#[ActionParameter(source: ParameterSource::query)]
?int $workspace = null,
): void {
// …
}
A parameter of type \TYPO3\CMS\Core\Action\UploadedContent gets the
content of an uploaded file, which the client sends as the raw request body. It
gives the content as $content->stream, its size and its media type from
the Content-Type header. An action can have one such parameter, and only for
the types create, dispatch and replace. The request can have any content
type. All other parameters are query parameters, and the OpenAPI document
describes the body as application/octet-stream. AI tools cannot send uploaded
content, so such an action must not have the target Target::ai:
use TYPO3\CMS\Core\Action\Target;
use TYPO3\CMS\Core\Action\UploadedContent;
#[AsAction(
route: 'my-extension/attachments',
type: ActionType::create,
targets: [Target::backend, Target::http],
)]
public function upload(UploadedContent $content, string $name): void
{
// …
}use TYPO3\CMS\Core\Action\Target;
use TYPO3\CMS\Core\Action\UploadedContent;
#[AsAction(
route: 'my-extension/attachments',
type: ActionType::create,
targets: [Target::backend, Target::http],
)]
public function upload(UploadedContent $content, string $name): void
{
// …
}