Sunteți pe pagina 1din 2

Extbase Cheat Sheet 1 GIT: git clone http://git.typo3.org/TYPO3v4/CoreProjects/MVC/extbase.git v 3.00 / 23.10.

2013
Forge: http://forge.typo3.org/projects/show/typo3v4-mvc Patrick Lobacher / www.typovision.de
Issue-Tracker: http://forge.typo3.org/projects/typo3v4-mvc/issues
creativecommons.org/licenses/by-sa/3.0 compatible with TYPO3 CMS >= 6.2

Domain Driven Design (terms by wikipedia) Folder structure inside extension dir typo3conf/ext/[extension_key]/ ExtensionUtility-API
Domain A sphere of knowledge, influence, or activity. ext_autoload.php Mapping classname to classfile location Frontend Plugin
Model A system of abstractions that describes selected aspects of a domain ext_emconf.php Extension manager configuration ext_tables.php \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
[Vendor]. . $_EXTKEY, // vendor + ext key
Ubiquitous Language A language structured around the domain model & used by all team members to connect all ext_icon.gif Extension icon PluginName, // plugin name
(UL) the activities of the team with the software. The words of the UL are used throughout all artefacts. ext_localconf.php Frontend configuration Plugin title, // plugin title
Entity An object that is not defined by its attributes, but rather by a thread of continuity and its identity. \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($extensionKey).
ext_tables.php Backend configuration Resources/Public/Icons/someIcon.gif // icon path (optional)
Derives from class \TYPO3\CMS\Extbase\DomainObject\AbstractEntity
ext_tables.sql SQL statements for the databse structure );
Value Object (VO) An object that contains attributes but has no conceptual identity. They should be treated as immu-
composer.json /ExtensionBuilder.json ExtensionBuilder configuration ext_localconf.php \TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
table. Derives from class \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject [Vendor]. . $_EXTKEY, // vendor + ext key
Classes/ All PHP classes reside here
Aggregate A collection of objects that are bound together by a root entity, known as an aggregate root. PluginName, // plugin name
Classes/Controller/[DomainObjectName]Controller.php Controller of model [DomainObjectName] (rec.) array( Controller1 => action1, action2, ..., // controller action
Aggregate root The aggregrate root guarantees the consistency of changes being made within the aggregate by Controller2 => action3, action4, ..., // combinations
forbidding external objects from holding references to its members. Classes/Domain/Model/[DomainObjectName].php Specific model class for [DomainObjectName] ...),
Repository Methods for retrieving domain objects should delegate to a specialized Repository object such that Classes/Domain/Repository/ Repository of model [DomainObjectName] array( Controller1 => action1, action2, ..., // controller action
alternative storage implementations may be easily interchanged. [DomainObjectName]Repository.php Controller2 => action3, action4, ..., // combinations uncached
...), // must be in 1st arr too
Derives from class \TYPO3\CMS\Extbase\Persistence\Repository Classes/Validation/Validator/ Validator of model [DomainObjectName] \TYPO3\CMS\Extbase\Utility\ExtensionUtility::TYPE_PLUGIN // or TYPE_CONTENT_ELEMENT
[DomainObjectName]Validator.php );
Naming Conventions Classes/ViewHelpers/[VHName]ViewHelper.php View helper with name VHName Backend Module
UpperCamelCase Directories, Classes, Files, ExtensionName (not extension_key!) Configuration/ All configuration (structure is a suggestion) ext_tables.php Tx_Extbase_Utility_Extension::registerModule(
lowerCamelCase Actions, Methods, Properties [Vendor]. . $_EXTKEY, // vendor + ext key
Configuration/TCA/ Table configuration array (TCA) web, // main module
Namespaces namespace [Vendor]\[ExtensionName]\Dir1\Dir2; ([Vendor] of TYPO3 is: TYPO3\CMS) Configuration/FlexForms/ Flexforms used for backend forms tx_extkey_m1, // sub module
Location is: [ExtBaseDir]/[extension_key]/Classes/Dir1/Dir2 $position, // see below
Configuration/TypoScript/ TypoScript constants and setup array( Controller1 => action1, action2, ..., // controller action
[ExtensionName] is [extension_key] without _ and in UpperCamelCase
[ExtBaseDir]: for own extensions it is typo3conf/ext/, for system extensions it is typo3/sysext/ Documentation/ All documentation reside here Controller2 => action3, action4, ..., // combinations
...),
FQCN Full Qualified Class Name Documentation/Manual/ Extension manual, subfolder [format]/[lang]/ array( // configuration array
e.g. \TYPO3\CMS\Extbase\Utility\ExtensionUtility Resources/ All resources reside here acces => user,group,
Path: typo3/sysext/extbase/Classes/Utility icon => EXT:extkey/ext_icon.gif,
Resources/Private/Backend/Layouts/ Layout files for backend modules labels => LLL:EXT:extkey/Resources/Private/Language/...
Classname: ExtensionUtility (namespace TYPO3\CMS\Extbase\Utility);
Class filename: ExtensionUtility.php Resources/Private/Backend/Templates/ All templates of a specific controller (BE) )
[ControllerName]/ );
$position has this syntax: [cmd]:[submodule-key]. cmd can be after, before or top (or
MISC Resources/Private/Backend/Templates/ Template of [action] from [Controller] (BE) blank - default). If after/before then submod will be inserted after/before the existing submod
FlashMessages ($this->controllerContext->getFlashMessageQueue()->) [ControllerName]/[action].[format] with [submodule-key] if found. If not, the bottom of list. If top the module is inserted in the top
of the submodule list.
Resources/Private/Language/locallang.xlf Main language file - use key w. translate viewhelper
enqueue($message) Adds a FlashMessage in the queue General functions
$message = new \TYPO3\CMS\Core\Messaging\FlashMessage($mes- Resources/Private/Layouts/ Layout files for frontend plugins
sage, $title = , $severity = \TYPO3\CMS\Core\Messaging\FlashMes- ext_tables.php // Static TypoScript
Resources/Private/Partials/ Partials files for frontend plugins
sage::OK, $storeInSession = FALSE) \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, Configu-
Severity: NOTICE, INFO, OK, WARNING, ERROR Resources/Private/Templates/[Controller]/[Action]. Template of [Action] from [Controller] (FE) ration/TypoScript, TS-Template Label);
[format] // Include flexforms
dequeue() Removes last FlashMessage from the queue
Resources/Public/ Additional resources (own dirs if needed, like Icons, ...) $pluginSignature = [extkey]_[pluginName];
getAllMessages() Gets all FlashMessages $TCA[tt_content][types][list][subtypes_addlist][$pluginSignature] = pi_flexform;
Tests/ All tests reside here
getAllMessagesAndFlush() Get all FlashMessages and removes them from the session \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPiFlexFormValue($pluginSigna-
ture,FILE:EXT:[extkey]/Configuration/FlexForms/flexform_bloglisting.xml);
Debugging Flexform (example option locallang.xlf and [iso].locallang.xlf // Allow data entries on standard pages (paramter is table name like tx_simpleblog...)
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(...) maxPosts and switchableCont- (in Resources/Private/Language) \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages(...);

Exceptions rollerActions)
<T3DataStructure> <switchableControllerActions>
PHPDoc annotations (always use FQCN - use statement is not enough!)
throw new \RuntimeException($text, 1363300072); // Unix-TS because of uniqueness
<sheets> <TCEforms>
Dependency Injection (DI) <sDEF> <label>Some label</label> @api Declares that the following class/method is part of the official API
<ROOT> <config>
/** <TCEforms> <type>select</type> @cascade remove Delete child(s) if parent is removed (use at property in domain model)
<sheetTitle>LLL:EXT:my_extension/ <items type=array>
* @var FQCN (Fully qualified class name) Resources/Private/Language/locallang_db.xm- <numIndex index=0 type=array> @deprecated Declares that the following class/method should not be used anymore
* @inject l:ff.sheetTitle</sheetTitle> <numIndex index=0>Default</numIndex>
*/ </TCEforms> <numIndex index=1>Controller1->action1; @dontverifyrequesthash Disable request hash checking (just used with old property mapper)
<type>array</type> Controller2->action2;...</numIndex>
protected $varName; <el> </numIndex> @ignorevalidation $var Action: No validation for $var (use @dontvalidate if old property mapper active)
DI Persistence Manager (persist all objects) - FQCN: \TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager </items>
...ELEMENTS... <maxitems>1</maxitems> @inject Executes the dependency injection (DI) of th class named in @var
<size>1</size>
$this->persistenceManager->persistAll(); </el> </config> @lazy Lazy loading in domain model (load child objects only when needed)
</ROOT> </TCEforms>
DI Object Manager (gets objects via DI) - FQCN: \TYPO3\CMS\Extbase\Object\ObjectManagerInterface </sDEF> </switchableControllerActions>
</sheets>
@param [Type] $var Action: Parameter. $var validates to [Type]
$this->objectManager->get([Vendor]\\[ExtensionName]\\[Path]\\[ClassName])->... </T3DataStructure>
$this->objectManager->getScope([Vendor]\\[ExtensionName]\\[Path]\\[ClassName])
@return [Type] Return value is of type [Type]
<settings.maxPosts> <?xml version=1.0 encoding=utf-8 standalone=yes ?>
DI Configuration Manager - FQCN: \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface <TCEforms> <xliff version=1.0> @validate [$var] [Validator] Model & Action: Validation for $var. In model without $var.
<label>Max. number of posts</label> <file source-language=en datatype=plaintext original=- Its possible to use shorthand notation: [ExtensionName]:[ValidatorName]
$this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationMana- <config> messages date=date product-name=[extensionkey]>
gerInterface::XXX,$extensionName=NULL, $pluginName=NULL) [XXX is CONFIGURATION_TYPE_FRAMEWORK,
<type>input</type> <header/> @var [Type] Model: Type of var in Domain Model - either simple type, class or ObjectStorage:
<size>2</size> <body>
CONFIGURATION_TYPE_SETTINGS, CONFIGURATION_TYPE_FULL_TYPOSCRIPT] | getContentObject() <eval>int</eval> <trans-unit id=key> \TYPO3\CMS\Extbase\Persistence\ObjectStorage
<default>10</default> <source>Original Text</source> <\[Vendor]\[ExtensionName]\Domain\Model\[Model]>
Translation </config> <target state=translated>Translated Text</target> delivers methods:
</TCEforms> </trans-unit>
\TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($key, $extensionName, $arguments = NULL) </settings.maxPosts> </body></file></xliff> count(), attach(), attachAll(), detach(), detachAll(), contains(), ...
Extbase Cheat Sheet 2 GIT: git clone http://git.typo3.org/TYPO3v4/CoreProjects/MVC/extbase.git v 3.00 / 23.10.2013
Forge: http://forge.typo3.org/projects/show/typo3v4-mvc Patrick Lobacher / www.typovision.de
Issue-Tracker: http://forge.typo3.org/projects/typo3v4-mvc/issues
creativecommons.org/licenses/by-sa/3.0 compatible with TYPO3 CMS >= 6.2

TypoScript ActionController API (\TYPO3\CMS\Extbase\Mvc\Controller\ActionController) Custom queries (use in own method inside repository)
CONSTANTS: plugin.tx_[lowercasedextensionname] & module.tx_[lowercasedextensionname] $this->actionMethodName Name of current action (Default: indexAction) $query = $this->createQuery();
$query = $query->matching(
view # cat=plugin.tx_myextension/file; type=string; label=Path to template root (FE) $this->defaultViewObjectName Default view: TYPO3\\CMS\\Fluid\\View\\TemplateView $query->logicalAnd(
templateRootPath = EXT:my_extension/Resources/Private/Templates/ $query->equals(blog, $blog),
$this->errorMethodName Name of error action (Default: errorAction)
persistence # cat=plugin.tx_myextension//a; type=int+; label=Default storage PID $query->equals(tags.name, $tag)
storagePid =
$this->request Request object (of type \TYPO3\CMS\Extbase\Mvc\RequestInterface) )
$this->response Response object (of type \TYPO3\CMS\Extbase\Mvc\ResponseInterface) )->setOrderings(array(date =>\TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCEN-
SETUP: plugin.tx_[lowercasedextensionname] & module.tx_[lowercasedextensionname] & config.tx_extbase DING))->setLimit((integer)$limit)
settings Access in controller: $this->settings $this->settings Domain specific settings from TypoScript (array) return $query->execute();
Access in Fluid: {settings} $this->view current view (of type \TYPO3\CMS\Extbase\Mvc\View\ViewInterface) $query = $this->createQuery(); Initializes a query. Access to below methods with $query->...
features rewrittenPropertyMapper Turn on new property mapper (TRUE) $this->namespacesViewObjectNamePattern @vendor\@extension\View\@controller\@action@format logicalAnd($constraints) Performs a logical conjunction of the given constraints
skipDefaultArguments Skip default arguments (FALSE) logicalOr($constraints) Performs a logical disjunction of the given constraints
function initializeView(\TYPO3\CMS\Extbase\ Initialize method for the commited view
ignoreAllEnableFieldsInBe Ignore enable fields in BE (FALSE) Mvc\View\ViewInterface $view) logicalNot($constraint) Performs a logical negation of the given constraint
persistence enableAutomaticCacheClearing Clear Cache at write operations (FALSE) function initializeAction() Initialize method for all actions statement($constraint) SQL-Statement
updateReferenceIndex Update refrence index (FALSE) get | setOrderings(array $orderings) \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING
function initialize[ActionName]Action() Initialize method for specific action [ActionName]
storagePid PID list where records are read from \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING
function [actionName]Action() Specific method for action [actionName] get | setLimit($limit) Sets the maximum size of the result set to limit (integer!)
persistence. newRecordStoragePid PID where new records will be stored
classes. mapping.tableName Which table is mapped function errorAction() Called at arguments validation error. get | setOffset($offset) Sets the start offset of the result set to offset (integer!)
[fullClassName]. mapping.recordType Record type (needs TCA field type => record_type), function resolveView() Prepares a view for the current action and stores it in $this->view getConstraint() Get the constraints back (if there are any)
mapping.columns. field_name. Which column in table is mapped function resolveViewObjectName() Determines the fully qualified view object name execute(FALSE) Executes the query against the backend and returns the result, TRUE = raw
mapOnProperty = field_name = field in table
propertyName propertyName = property in model $this->forward($actionName, $controllerNa- Internal redirect of request to another controller count() Get the first result back / $count = $query->execute()->count()
me, $extensionName, array $arguments)
subclasses. put one entry for every subclass in superclass definition getFirst() Get the first result back / $first = $query->execute()->getFirst()
[Identifier] = [fullClassName]
$this->redirect($actionName, $controller- External HTTP redirect to another controller
Name, $extensionName, array $arguments, matching($constraints) The constraint used to limit the result set. Use methods below...
view templateRootPath Template path (templateRootPaths.ARRAY = fallbackpath) $pageUid, $delay = 0, $statusCode = 303) equals($propertyName, $operand, Returns an equals criterion used for matching objects against a query
partialRootPath Partial path (partialRootPaths.ARRAY = fallbackpath) $this->redirectToURI($uri, $delay=0, $statusCode=303) Redirect to URI $caseSensitive = TRUE)
layoutRootPath Layout path (layoutRootPaths.ARRAY = fallbackpath) like($propertyName, $operand) Returns an equals criterion used for matching objects against a query
$this->throwStatus($statusCode, $status- Send HTTP status code
_LOCAL_LANG [ISOlang].key Localization (key corresponds to the key in file: Message, $content) contains($propertyName, $operand) It matches if the multivalued property contains the given operand
[default].key Resources/Private/Language/locallang.xlf)
in($propertyName, $operand) It matches if the propertys value is contained in the multivalued operand
_CSS_DEFAULT_STYLE Inline stylesheets Repository API (\TYPO3\CMS\Extbase\Persistence\Repository) lessThan($propertyName, $operand) Returns a less than criterion used for matching objects against a query
SETUP: config.tx_extbase Include plugin via TS $defaultOrderings = array (pro=>sorting) Default order. Property and sorting (see custom query) is needed. lessThanOrEqual ($propertyName, $operand) Returns a less or equal than criterion used for matching objects against a query
objects. At all places where the code lib.foo = USER greaterThan($propertyName, $operand) Returns a greater than criterion used for matching objects against a query
$defaultQuerySettings Repository wide settings ($this->createQuery()->getQuerySettings())
[sourceClass]. refers to [sourceClass], an lib.foo { greaterThanOrEqual($propertyName,$operand) Returns a greater than or equal criterion used for matching objects against a query
userFunc = TYPO3\CMS\Extbase\Core\Bootstrap->run $query->getQuerySettings()-> (TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface)
className = object of [targetClass] should
extensionName = [ExtensionName] ->setRespectStoragePage ->setLanguageUid
[targetClass] be instantiated. pluginName = [PluginName] ->setStoragePageIds ->setIgnoreEnableFields Validator API (TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator)
mvc. Configures the 3 request vendorName = [VendorName] ->setRespectSysLanguage ->setEnableFieldsToBeIgnored In annotation of Domain Model: @validate Validator1, Validator2(operand1 = value1, ...), ...
requestHandlers handlers for FE, BE, CLI controller = [ControllerName] ->setLanguageOverlayMode ->setIncludeDeleted Validator class for Domain Model: class [Vendor]\[ExtensionName]\Validation\Validator\[DomainModelName]Validator
action = [actionName] ->setLanguageMode extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator
switchableControllerActions { Validation of controller arguments: @validate $variableName Validator1, Validator2, ...
[ControllerName] { add($object) Add object to repository
Alphanumeric TRUE, if the given property is a valid alphanumeric string [a-zA-Z0-9]*
1 = [actionName] countAll() Returns the total number objects of this repository
2 = [anotherActionName] Boolean(is=true|false) Checks if the given value is true or false
countBy[PropertyName]($propertyValue) Returns the number objects with [PropertyName] == $propertyValue
createQuery() Creates a query (see custom queries)
Conjunction / Disjunction AND/OR: Con/Disjunction(0=Validator1,1=Validator2, ...)
View API (\TYPO3\CMS\Extbase\Mvc\View\ViewInterface) DateTime Checks if the given value is a valid DateTime object
findByUid($uid) Finds an object matching the given identifier
$this->view->assign($key,$value) Assign $value to key $key in view
findAll() Find all objects of given type EmailAddress Checks if the given value is a valid email address
$this->view->assignMultiple(array $values) Assign array $values view - use key of array element for key in view
findBy[PropertyName]($propertyValue) Find all objects where property [PropertyName] == $propertyValue Float Checks if the given value is a valid float
$this->view->initializeView() Initializing the concrete view implementation
findOneBy[PropertyName]($propertyValue) Same as above, just find one (the first found) object (type object!) Integer Checks if the given value is a valid integer
$this->view->render() Returns the rendered view
remove($object) Remove object from repository NotEmpty Checks if the given value is not empty (NULL or empty string)
Request API (\TYPO3\CMS\Extbase\Mvc\RequestInterface) $this->request removeAll() Removes all objects of this repository NumberRange(startRange,endRange) Returns TRUE, if the given value is a valid number in the given range
get set Argument($argumentName, $value) Gets/Sets the value of the specified argument setDefaultOrderings(array $defOrderings) Sets the default orderings Number Checks if the given value is a valid number
get set Arguments(array $arguments) Gets/Sets the whole arguments array
setDefaultQuerySettings(...) Sets the default query settings: type of ...\QuerySettingsInterface
RegularExpression(regularExpression) Returns TRUE, if the given value matches the given regular expression
update($object) Update stored object with $object
is set Dispatched Get/Sets the dispached flag for the request StringLength(minimum,maximum) Returns TRUE, if the given property ($value) is a valid string and its length
get set ControllerActionName($actionName) Gets/Sets the name of the action UriBuilder API (TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder) String Returns TRUE, if the given property ($value) is a valid string
get ControllerExtensionKey() Returns the extension name of the specified controller Access in controller via $this->uriBuilder->... Text Returns TRUE, if the given property ($propertyValue) is a valid text
get set ControllerExtensionName($extensionName) Gets/Sets the extension name of the controller section = | format = | createAbsoluteUri = FALSE | addQueryString = UriBuilder Options Prop Validator (@validate \[VendorName]\[ExtensionName]\Validation\Validator\[ValName]Validator(option=value))
get set ControllerName($controllerName) Gets/Sets the name of the controller FALSE | addQueryStringMethod = | linkAccessRestrictedPages = FALSE
| argumentsToBeExcludedFromQueryString = array() | targetPageUid = there are Getter and Setter for all namespace [VendorName]\[ExtensionName]\Validation\Validator;
class ValNameValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
get set ControllerObjectName($controllerName) Gets/Sets the object name of the controller NULL | targetPageType = 0 | noCache = FALSE | useCacheHash = TRUE of them public function isValid($property) {
$option1 = $this->options[option1]; // options access
get set ControllerSubpackageKey($subpackageKey) Gets/Sets the subpackage key of the controller setRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request) Sets/Gets request $this->addError(ErrorString, 1262341470,$arguments,$title); // type \TYPO3\CMS\Extbase\Validation\Error
getRequest() return TRUE; // or FALSE // validates if TRUE
get set ControllerVendorName($vendorName) Gets/Sets the vendor name of the controller }
reset() Resets all UriBuilder options to default }
hasArgument($argumentName) Checks if an argument of the given name exists (is set)
uriFor($actionName = NULL, $controllerArguments = array(), $cont- Creates an URI used for linking to an DO Validator ([VendorName]\[ExtensionName]\Validation\Validator\[DomainModelName]Validator) - e.g. for prop. title
get set Format($format) Gets/Sets requested representation format rollerName = NULL, $extensionName = NULL, $pluginName = NULL) Extbase action
$error = $this->objectManager->get(TYPO3\\CMS\\Extbase\\Validation\\Error, $apiValidationResult[title], time());
get set PluginName($pluginName) Gets/Sets the plugin name of the controller build() Builds the URI $this->result->forProperty(title)->addError($error);

S-ar putea să vă placă și