Attention
TYPO3 v11 has reached end-of-life as of October 31th 2024 and is no longer being maintained. Use the version switcher on the top left of this page to select documentation for a supported version of TYPO3.
Need more time before upgrading? You can purchase Extended Long Term Support (ELTS) for TYPO3 v11 here: TYPO3 ELTS.
Annotations
All available annotations for Extbase delivered by TYPO3 Core are placed within
the namespace \TYPO3\
.
Example in the blog example for the annotation Lazy
:
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class Post extends AbstractEntity
{
/**
* @var ObjectStorage<Post>
* @Lazy
*/
public ObjectStorage $relatedPosts;
}
Annotations provided by Extbase
The following annotations are provided Extbase:
Validate
@TYPO3\
: Allows to configure validators
for properties and method arguments. See Validation for details.
Can be used in the context of a model property.
Example:
use TYPO3\CMS\Extbase\Annotation\Validate;
class Blog extends AbstractEntity
{
/**
* A short description of the blog
*
* @Validate("StringLength", options={"maximum": 150})
*/
public string $description = '';
}
IgnoreValidation
@TYPO3\
: Allows to ignore
Extbase default validation for a given argument.
Used in context of a controller action.
Example:
use FriendsOfTYPO3\BlogExample\Domain\Model\Blog;
use Psr\Http\Message\ResponseInterface;
use TYPO3\CMS\Extbase\Annotation\IgnoreValidation;
class BlogController extends AbstractController
{
/**
* Displays a form for creating a new blog
*
* @IgnoreValidation("newBlog")
*/
public function newAction(?Blog $newBlog = null): ResponseInterface
{
$this->view->assign('newBlog', $newBlog);
$this->view->assign(
'administrators',
$this->administratorRepository->findAll()
);
return $this->htmlResponse();
}
}
ORM (object relational model) annotations
The following annotations can only be used on model properties:
Cascade
@TYPO3\
: Allows to remove
child entities during deletion of aggregate root.
Extbase only supports the option "remove".
Example:
use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class Blog extends AbstractEntity
{
/**
* The posts of this blog
*
* @var ObjectStorage<Post>
* @Lazy
* @Cascade("remove")
*/
public $posts;
}
Transient
@TYPO3\
: Marks property as transient
(not persisted).
Example:
use TYPO3\CMS\Extbase\Annotation\ORM\Transient;
class Person extends AbstractEntity
{
/**
* @Transient
*/
protected string $fullname = '';
}
Lazy
@TYPO3\
: Marks property to be lazily
loaded on first access.
Note
Lazy loading can greatly improve the performance of your actions.
Example:
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class Post extends AbstractEntity
{
/**
* @var ObjectStorage<Post>
* @Lazy
*/
public ObjectStorage $relatedPosts;
}
Combining annotations
Annotations can be combined. For example, "lazy loading" and "removal on cascade" are frequently combined:
use TYPO3\CMS\Extbase\Annotation\ORM\Cascade;
use TYPO3\CMS\Extbase\Annotation\ORM\Lazy;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
class Post extends AbstractEntity
{
/**
* @var ObjectStorage<Comment>
* @Lazy
* @Cascade("remove")
*/
public ObjectStorage $comments;
}
Several validations can also be combined. See Validation for details.