Jan 15, 2015 Tags: Extbase, TYPO3

Looking for Wisdom about Extbase

Ongoing attempt to collect links and documentation about TYPO3 Extbase. Will be updated as needed.

Updated on Sep 10, 2015

Navigate this page:

About Extbase Documentation

Incoming

2013-04-08

Query

Videos

Coding

Coding tips

Debug and watch SQL queries

This works reliably:

$GLOBALS['TYPO3_DB']->debugOutput = 2;
$query->execute()->toArray(); //
$GLOBALS['TYPO3_DB']->debugOutput = FALSE;

What folder names people use for Classes

Examples:

extension
   Classes
      Ajax
      AjaxHandler
      Component
      Configuration
      Controller
      Debugger
      Dispatch
      Domain
      Eid
      Exceptions
      ExtDirect
      Finisher
      Generator
      Interceptor
      Hooks
      Logger
      Mailer
      Parser
      PreProcessor
      Provider
      Reports
      Services
      Session
      Slots
      Tca
      TCA
      Temp
      UserConditions
      UserFunctions
      Utility
      Utils
      Validator
      ViewHelpers
      View
      Xclass/Backend/View

Sessions

http://docs.typo3.org/typo3cms/TyposcriptReference/6.0/AppendixC/StoringData/Index.html#appendix-storing-data

$GLOBALS['TSFE']->fe_user->setKey("ses","key",$value)
...
$GLOBALS["TSFE"]->fe_user->getKey("user","key")
if ($GLOBALS['TSFE']->loginUser) {
   $myData = $GLOBALS['TSFE']->fe_user->getKey('user', 'myData');
} else {
   $myData = $GLOBALS['TSFE']->fe_user->getKey('ses', 'myData');
}

Static TypoScript

# configure this extension (frontend)
plugin.tx_[lowercasedextensionname] {

   #view
   #persistence
   #objects
   #
   #
   #
   #settings
   #_LOCAL_LANG
   #_CSS_DEFAULT_STYLE

}

# configure this extension (backend)
module.tx_[lowercasedextensionname] {
   #view
   #persistence
   #
   #
   #
   #
   #settings
   #_LOCAL_LANG
   #_CSS_DEFAULT_STYLE
}

# configure extbase (all extensions, front- and backend)
config.extbase {
   #view
   #persistence
   #objects
   #features
   #mvc
   #legacy
   #settings
   #_LOCAL_LANG
   #_CSS_DEFAULT_STYLE
}

SETUP: plugin.tx_[lowercasedextensionname] & module.tx_[lowercasedextensionname] & confi g.tx_extbase

settings {
   # $this-> settings in controller
   # {settings} in Fluid
}

features {
   rewrittenPropertyMapper = TRUE
   skipDefaultArguments = FALSE
   ignoreAllEnableFieldsInBe = FALSE
}

persistence {
   classes {
      [fullClassName] {
         newRecordStoragePid =
         mapping {
            tableName =
            recordType =
            columns {
               field_name.mapOnProperty = propertyName
            }
         }
      }
   }
}

view {
   templateRootPath =
   partialRootPath =
   layoutRootPath =
}

_LOCAL_LANG {
   # Resources/Private/Language/locallang.xlf
   [ISOlang].key =
   [default].key =
}

_CSS_DEFAULT_STYLE {
   # inline styles
}

Validation

Chapters for the Extbase Reference

Validator API

TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator

Alphanumeric

TRUE, if the given property is a valid alphanumeric string [a-zA-Z0-9]*

@validate Alphanumeric

Boolean(is=true|false)

Checks if the given value is true or false

Conjunction

AND: Conjunction(0=Validator1,1=Validator2, ...)

DateTime

Checks if the given value is a valid DateTime object

Disjunction

OR: Disjunction(0=Validator1,1=Validator2, ...)

EmailAddress

Checks if the given value is a valid email address

@validate EmailAddress

Float

Checks if the given value is a valid float

Integer

Checks if the given value is a valid integer

NotEmpty

Checks if the given value is not empty (NULL or empty string)

@validate NotEmpty

NumberRange(startRange,endRange)

Returns TRUE, if the given value is a valid number in the given range

Old (<=6.2):

@validate NumberRange(minimum=10, maximum=100)
// with fallback for startRange, endRange
@validate NumberRange(startRange=10, endRange=100)

New (>=7.0):

@validate NumberRange(minimum=10, maximum=100)

Number

Checks if the given value is a valid number

RegularExpression(regularExpression)

Returns TRUE, if the given value matches the given regular expression

@validate RegularExpression(regularExpression='/(Hello|Goodbye) World!/i')

StringLength(minimum,maximum)

Returns TRUE, if the given property ($value) is a valid string and its length

@validate StringLength(minimum=10, maximum=100)

String

Returns TRUE, if the given property ($value) is a valid string

Text

Returns TRUE, if the given property ($propertyValue) is a valid text

Builtin Validators 6.2

Taken from the source:

AbstractObject

API typo3\cms\extbase\validation\validator\abstractobjectvalidator

Alphanumeric

The given $value is valid if it is an alphanumeric string, which is defined as [\pL\d]*.

API \TYPO3\CMS\Extbase\Validation\Validator\AlphanumericValidator

Boolean

Returns TRUE if the given property value is a boolean matching the expectation.

API \TYPO3\CMS\Extbase\Validation\Validator\BooleanValidator

Supported options:

'is' => array(NULL, 'Boolean value', 'boolean|string|integer')

Collection

Checks for a collection and if needed validates the items in the collection.

API \TYPO3\CMS\Extbase\Validation\Validator\CollectionValidator

Supported options:

'elementValidator' => array(NULL, 'The validator type to use for the collection elements', 'string'),
'elementType'      => array(NULL, 'The type of the elements in the collection'           , 'string'),
'validationGroups' => array(NULL, 'The validation groups to link to'                     , 'string'),

DateTime

Make sure value is a valid DateTime object.

API \TYPO3\CMS\Extbase\Validation\Validator\DateTimeValidator

Disjunction

Make sure, at least one validator is valid.

API \TYPO3\CMS\Extbase\Validation\Validator\DisjunctionValidator

Float

The given value is valid if it is of type float or a string matching the regular expression [0-9.e+-].

API \TYPO3\CMS\Extbase\Validation\Validator\FloatValidator

Integer

Ensure that value is a valid integer.

API \TYPO3\CMS\Extbase\Validation\Validator\IntegerValidator

NotEmpty

Checks if the given property ($propertyValue) is not empty (NULL, empty string, empty array or empty object).

API \TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator

NumberRange

API \TYPO3\CMS\Extbase\Validation\Validator\NumberRangeValidator

Supported options:

'minimum' => array(0, 'The minimum value to accept', 'integer'),
'maximum' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer'),
'startRange' => array(0, 'The minimum value to accept', 'integer'),
'endRange' => array(PHP_INT_MAX, 'The maximum value to accept', 'integer')

Raw

Always valid, nothing is checked.

API \TYPO3\CMS\Extbase\Validation\Validator\RawValidator

RegularExpression

Ensure the given value matches the specified regular expression.

API \TYPO3\CMS\Extbase\Validation\Validator\RegularExpressionValidator

Supported options:

'regularExpression' => array('', 'The regular expression to use for validation, used as given',
                             'string', TRUE)

StringLength

Checks if the given value is a valid string (or can be cast to a string if an object is given) and its length is between minimum and maximum specified in the validation options.

API \TYPO3\CMS\Extbase\Validation\Validator\StringLengthValidator

Supported options:

'minimum' => array(0, 'Minimum length for a valid string', 'integer'),
'maximum' => array(PHP_INT_MAX, 'Maximum length for a valid string', 'integer')

Text

Ensure value is a valid text without XML tags.

API \TYPO3\CMS\Extbase\Validation\Validator\TextValidator

PHPDoc Annotations

Annotation Description
@api Declares that the following class or method is part of the official API
@cascade remove Delete child(s) if parent is removed (use at property in domain model)
@deprecated Declares that the following class or method should not be used anymore
@dontverifyrequesthash Disable request hash checking (just used with old property mapper)
@ignorevalidation $var Action: No validation for $var (use @dontvalidate if old property mapper active)
@inject Executes the dependency injection (DI) of th class named in @var
@lazy Lazy loading in domain model (load child objects only when needed)
@param [Type] $var Action: Parameter. $var validates to [Type]
@return [Type] Return value is of type [Type]
@validate [$var] [Validator] Model & Action: Validation for $var. In model without $var. It‘s possible to use shorthand notation: [ExtensionName]:[ValidatorName]
@var [Type] [1]

[1] Model: Type of var in Domain Model - either simple type, class or ObjectStorage:

\TYPO3\CMS\Extbase\Persistence\ObjectStorage
 <\[Vendor]\[ExtensionName]\Domain\Model\[Model]

delivers methods: count(), attach(), attachAll(), detach(), detachAll(), contains(), ...

Not Obvious

“Virtual” Properties

To use properties that are not stored persistently:

  1. do not define them in the sql code
  2. do not define them in the TCA

That’s enough!

propertyMappingConfiguration

  • https://www.google.de/search?q=typo3+propertymappingconfiguration

  • snippet in2code !!!

    protected function initializeUpdateAction() {
       $mvcPropertyMappingConfiguration = \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationBuilder::build('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfiguration');
       $this->arguments->getArgument('mother')->injectPropertyMappingConfiguration($mvcPropertyMappingConfiguration);
       $propertyMappingConfiguration = $this->arguments->getArgument('mother')->getPropertyMappingConfiguration();
       $propertyMappingConfiguration->forProperty('*')->allowAllProperties();
       $propertyMappingConfiguration->forProperty('*')->allowCreationForSubProperty('*');
       $propertyMappingConfiguration->forProperty('*')->forProperty('*')->allowAllProperties();
    }
    

Comments

comments powered by Disqus

Previous topic

Looking for Wisdom about Cryptography

Next topic

Looking for Wisdom about Fluid

Tags

Archives

Languages

Recent Posts

This Page