Mar 12, 2015 Tags: Extbase, TYPO3

Extbase API: Main Focus: The Controller

Updated on Apr 07, 2015

Overview:

AbstractController

AbStractController:

// ...
$abstractController = AbStractController();

__construct():

// ...
$abstractController->__construct();

addBaseUriIfNecessary():

// ...
$abstractController->addBaseUriIfNecessary();

addFlashMessage():

/**
 * Creates a Message object and adds it to the FlashMessageQueue.
 *
 * Parameters
 *    string   $messageBody     The message
 *    string   $messageTitle    Optional message title
 *    integer  $severity        Optional severity, must be one of constants
 *    boolean  $storeInSession  Optional, defines whether the message should be stored in the session (default) or not
 */


$void = $abstractController->addFlashMessage(
   $messageBody,
   $messageTitle = '',
   $severity = \TYPO3\CMS\Core\Messaging\AbstractMessage::OK, // NOTICE, INFO, OK, WARNING, ERROR
   $storeInSession = TRUE
);

canProcessRequest();:

// ...
$abstractController->canProcessRequest();

forward():

/* Forwards the request to another action and / or controller.
 *
 * Request is directly transfered to the other action / controller without the need for a new request.
 *
 * Parameters
 *    string  $actionName      Name of the action to forward to
 *    string  $controllerName  Unqualified object name of the controller to forward to. If not specified, the current controller is used.
 *    string  $extensionName   Name of the extension containing the controller to forward to. If not specified, the current extension is assumed.
 *    array   $arguments       Arguments to pass to the target action
 */

$void = $abstractController->forward( $actionName,
   $controllerName = NULL,
   $extensionName = NULL,
   array $arguments = NULL
);

getControllerContext():

// ...
$abstractController->getControllerContext();

initializeControllerArgumentsBaseValidators():

// ...
$abstractController->initializeControllerArgumentsBaseValidators();

injectConfigurationManager():

// ...
$abstractController->injectConfigurationManager();

injectFlashMessageContainer():

// ...
$abstractController->injectFlashMessageContainer();

injectObjectManager():

// ...
$abstractController->injectObjectManager();

processRequest():

// ...
$abstractController->processRequest();

redirect():

/**
 * Redirects the request to another action and / or controller.
 *
 * Redirect will be sent to the client which then performs another request to the new URI.
 *
 * NOTE: This method only supports web requests and will throw an exception if used with other request types.
 *
 * Parameters
 *     string   $actionName      Name of the action to forward to
 *     string   $controllerName  Unqualified object name of the controller to forward to. If not specified, the current controller is used.
 *     string   $extensionName   Name of the extension containing the controller to forward to. If not specified, the current extension is assumed.
 *     array    $arguments       Arguments to pass to the target action
 *     integer  $pageUid         Target page uid. If NULL, the current page uid is used
 *     integer  $delay           (optional) The delay in seconds. Default is no delay.
 *     integer  $statusCode      (optional) The HTTP status code for the redirect. Default is "303 See Other
 */

$void = $abstractController->redirect( $actionName,
   $controllerName = NULL,
   $extensionName = NULL,
   array $arguments = NULL,
   $pageUid = NULL,
   $delay = 0,
   $statusCode = 303
);

redirectToUri():

// ...
$abstractController->redirectToUri();

throwStatus():

// ...
$abstractController->throwStatus();

ActionController

\TYPO3\CMS\Extbase\Mvc\Controller\ActionController

$actionController = $this;();:

// ...
$actionController = $this;();

callActionMethod();:

// ...
$actionController->callActionMethod();

canProcessRequest();:

// ...
$actionController->canProcessRequest();

checkRequestHash();:

// ...
$actionController->checkRequestHash();

clearCacheOnError();:

// ...
$actionController->clearCacheOnError();

errorAction();:

// ...
$actionController->errorAction();

getActionMethodParameters();:

// ...
$actionController->getActionMethodParameters();

getErrorFlashMessage();:

// ...
$actionController->getErrorFlashMessage();

getViewProperty();:

// ...
$actionController->getViewProperty();

initializeAction();:

// ...
$actionController->initializeAction();

initializeActionMethodArguments();:

// ...
$actionController->initializeActionMethodArguments();

initializeActionMethodValidators();:

// ...
$actionController->initializeActionMethodValidators();

initializeView();:

// ...
$actionController->initializeView();

processRequest();:

// ...
$actionController->processRequest();

resolveActionMethodName();:

// ...
$actionController->resolveActionMethodName();

resolveViewObjectName();:

// ...
$actionController->resolveViewObjectName();

setViewConfiguration();:

// ...
$actionController->setViewConfiguration();

controllerContext

$actionController->getControllerContext():

// Get the controllerContext
$controllerContext = $actionController->getControllerContext();

$controllerContext->getArguments():

// Get the arguments of the controller
$controllerContext->getArguments();

// Get the flash messages
$controllerContext->getFlashMessageContainer();

$controllerContext()->getArgumentsMappingResults():

// Deprecated: Get the arguments mapping results of the controller
$cetControllerContext->getArgumentsMappingResults();

$controllerContext()->getFlashMessageContainer():

// Deprecated: Get the flash messages
$controllerContext->getFlashMessageContainer();

$controllerContext()->getFlashMessageQueue():

$controllerContext->getFlashMessageQueue();

$controllerContext->getRequest():

// Get the request of the controller
$controllerContext->getRequest();

$controllerContext->getResponse():

// Get the response of the controller
$controllerContext->getResponse();

$controllerContext->getUriBuilder():

$controllerContext->getUriBuilder();

$controllerContext->setArguments():

// Set the arguments of the controller
$controllerContext->setArguments( \TYPO3\CMS\Extbase\Mvc\Controller\Arguments $arguments);

$controllerContext->setArgumentsMappingResults():

// Deprecated: Set the arguments mapping results of the controller
$controllerContext->setArgumentsMappingResults( \TYPO3\CMS\Extbase\Property\MappingResults $argumentsMappingResults);

$controllerContext->setFlashMessageContainer():

// Deprecated: Set the flash messages
$controllerContext->setFlashMessageContainer( \TYPO3\CMS\Extbase\Mvc\Controller\FlashMessageContainer $flashMessageContainer);

$controllerContext->setRequest():

// Set the request of the controller
$controllerContext->setRequest( \TYPO3\CMS\Extbase\Mvc\Request $request);

$controllerContext->setResponse():

// Set the response of the controller
$controllerContext->setResponse( \TYPO3\CMS\Extbase\Mvc\Response $response);

$controllerContext->setUriBuilder():

$controllerContext->setUriBuilder( \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder $uriBuilder);

$controllerContext->useLegacyFlashMessageHandling():

// Deprecated:
$controllerContext->useLegacyFlashMessageHandling();

request

$request:

// Get the request
$request = $actionController->getControllerContext()->getRequest();

$request->getArgument():

// ...
$request->getArgument();

$request->getArguments():

// ...
$request->getArguments();

$request->getControllerActionName():

// ...
$request->getControllerActionName();

$request->getControllerExtensionKey():

// ...
$request->getControllerExtensionKey();

$request->getControllerExtensionName():

// ...
$request->getControllerExtensionName();

$request->getControllerName():

// ...
$request->getControllerName();

$request->getControllerObjectName():

// ...
$request->getControllerObjectName();

$request->getControllerSubpackageKey():

// ...
$request->getControllerSubpackageKey();

$request->getControllerVendorName():

// ...
$request->getControllerVendorName();

$request->getErrors():

// ...
$request->getErrors()

$request->getFormat():

// ...
$request->getFormat()

$request->getInternalArgument():

// ...
$request->getInternalArgument()

$request->getInternalArguments():

// ...
$request->getInternalArguments()

$request->getOriginalRequest():

// ...
$request->getOriginalRequest()

$request->getOriginalRequestMappingResults():

// ...
$request->getOriginalRequestMappingResults()

$request->getPluginName():

// ...
$request->getPluginName()

$request->hasArgument():

// ...
$request->hasArgument()

$request->isDispatched():

// ...
$request->isDispatched()

$request->setArgument():

// ...
$request->setArgument()

$request->setArguments():

// ...
$request->setArguments()

$request->setControllerActionName():

// ...
$request->setControllerActionName()

$request->setControllerExtensionName():

// ...
$request->setControllerExtensionName();

$request->setControllerName():

// ...
$request->setControllerName();

$request->setControllerObjectName():

// ...
$request->setControllerSubpackageKey();

$request->setControllerSubpackageKey():

// ...
$request->setControllerVendorName();

$request->setControllerVendorName():

// ...
$request->setDispatched();

$request->setDispatched():

// ...
$request->setDispatched();

$request->setErrors():

// ...
$request->setErrors();

$request->setFormat():

// ...
$request->setFormat();

$request->setOriginalRequest():

// ...
$request->setOriginalRequest();

$request->setOriginalRequestMappingResults():

// ...
$request->setOriginalRequestMappingResults();

$request->setPluginName():

// ...
$request->setPluginName();

mappingResult

$mappingResults:

$mappingResults = $actionController->getControllerContext()->getArgumentsMappingResults();
$mappingResults = $actionController->getControllerContext()->getRequest()->getOriginalRequestMappingResults();

$mappingResults->addError():

// ...
$mappingResults->addError();

$mappingResults->addWarning:

// ...
$mappingResults->addWarning();

$mappingResults->getErrors:

// ...
$mappingResults->getErrors();

$mappingResults->getWarnings:

// ...
$mappingResults->getWarnings();

$mappingResults->hasWarnings:

// ...
$mappingResults->hasErrors();

$mappingResults->hasWarnings:

// ...
$mappingResults->hasWarnings();

Code for enlightment:

/**
* Initialize all actions
*/
public function initializeAction() {
   $this->Mbless = array('dbg'=>array());
   $this->Mbless['dbg']['controllerContext'] = $this->
}

public function someAction() {
   if (1) {
      $mappingResults = $this->getControllerContext()->getArgumentsMappingResults();
      $mappingResultsOr = $this->getControllerContext()->getRequest()->getOriginalRequestMappingResults();
      $this->Mbless = array();
      $this->Mbless['dbg'] = array();
      if ($mappingResults) {
         $this->Mbless['dbg']['mR_errors']        = $mappingResults  ->getErrors();
         $this->Mbless['dbg']['mR_warnings']      = $mappingResults  ->getWarnings();
         $this->Mbless['dbg']['mR_hasErrors']     = $mappingResults  ->hasErrors();
         $this->Mbless['dbg']['mR_hasWarnings']   = $mappingResults  ->hasWarnings();
      }
      if ($mappingResultsOr) {
         $this->Mbless['dbg']['mRoR_errors']      = $mappingResultsOr->getErrors();
         $this->Mbless['dbg']['mRoR_warnings']    = $mappingResultsOr->getWarnings();
         $this->Mbless['dbg']['mRoR_hasErrors']   = $mappingResultsOr->hasErrors();
         $this->Mbless['dbg']['mRoR_hasWarnings'] = $mappingResultsOr->hasWarnings();
      }
   }
}

Argument

$argument:

$argument = $actionController->getControllerContext()->getArguments()->getArgument();

__construct:

$argument->__construct();

__toString:

$argument->__toString();

findObjectByUid:

$argument->findObjectByUid();

getDataType:

$argument->getDataType();

getDefaultValue:

$argument->getDefaultValue();

getName:

$argument->getName();

getOrigin:

$argument->getOrigin();

getPropertyMappingConfiguration:

$argument->getPropertyMappingConfiguration();

getShortName:

$argument->getShortName();

getValidationResults:

$argument->getValidationResults();

getValidator:

$argument->getValidator();

getValue:

$argument->getValue();

injectReflectionService:

$argument->injectReflectionService();

injectTypeHandlingService:

$argument->injectTypeHandlingService();

isRequired:

$argument->isRequired();

isValid:

$argument->isValid();

isValue:

$argument->isValue();

setDataType:

$argument->setDataType();

setDefaultValue:

$argument->setDefaultValue();

setNewValidatorConjunction:

$argument->setNewValidatorConjunction();

setRequired:

$argument->setRequired();

setShortName:

$argument->setShortName();

setValidator:

$argument->setValidator();

setValue:

$argument->setValue();

transformValue:

$argument->transformValue();

Arguments

Class Arguments:

$arguments = $actionController->getControllerContext()->getArguments();

__call():

$arguments->__call();

__construct():

$arguments->__construct();

addArgument():

$arguments->addArgument();

append():

$arguments->append();

getArgument():

/*
 * Returns an argument specified by name
 *
 * Parameters
 *    string  $argumentName  Name of the argument to retrieve
 */

$argument = $arguments->getArgument($argumentName);

// good
if ($arguments->hasArgument($someName)) {
   $argument = $arguments->getArgument($someName);
}

// bad: may throw an exception
$argument = $arguments->getArgument($someName);

getArgumentNames():

$arguments->getArgumentNames();

getArgumentShortNames():

$arguments->getArgumentShortNames();

getValidationResults():

// Get all property mapping / validation errors
$typo3CmsExtbaseErrorResult = $arguments->getValidationResults();

hasArgument():

$arguments->hasArgument();

offsetExists():

$arguments->offsetExists();

offsetGet():

$arguments->offsetGet();

offsetSet():

$arguments->offsetSet();

offsetUnset():

$arguments->offsetUnset();

removeAll():

$arguments->removeAll();

translateToLongArgumentName():

$arguments->translateToLongArgumentName();

ValidationResults

$validationResults:

$validationResults = $actionController->getControllerContext()->getArguments()->getValidationResults();

addError():

$validationResults->addError();

addNotice():

$validationResults->addNotice()

addWarning():

$validationResults->addWarning();

clear():

$validationResults->clear();

flattenTree():

$validationResults->flattenTree();

forProperty():

/**
 * Return a Result object for the given property path. This is a
 * fluent interface, so you will proboably use it like:
 *
 *    $fooBarErrors = $validationResults->forProperty('foo.bar')->getErrors();
 *
 * to get all errors for property "foo.bar"
 *
 * Parameters:
 *    string  $propertyPath
 */

$validationResults->forProperty( $propertyPath );

getErrors():

$validationResults->getErrors();

getFirstError():

$validationResults->getFirstError();

getFirstNotice():

$validationResults->getFirstNotice();

getFirstWarning():

$validationResults->getFirstWarning();

getFlattenedErrors():

/**
 * Get a list of all Error objects recursively.
 *
 * The result is an array, where the key is the property path where
 * the error occurred, and the value is a list of all errors
 * (stored as array).
 */

$resultArray = $validationResults->getFlattenedErrors();

getFlattenedNotices():

$validationResults->getFlattenedNotices();

getFlattenedWarnings():

$validationResults->getFlattenedWarnings();

getNotices():

$validationResults->getNotices();

getSubResults():

$validationResults->getSubResults();

getWarnings():

$validationResults->getWarnings();

hasErrors():

// Does the current Result object have Errors? (Recursively)

$bool = $validationResults->hasErrors();

hasMessages():

$validationResults->hasMessages();

hasNotices():

$validationResults->hasNotices();

hasProperty():

$validationResults->hasProperty();

hasWarnings():

$validationResults->hasWarnings();

mergeProperty():

$validationResults->mergeProperty();

recurseThroughResult():

// Internal use only!

$validationResults->recurseThroughResult( array $pathSegments );

setErrorsExist():

$validationResults->setErrorsExist();

setNoticesExist():

$validationResults->setNoticesExist();

setParent():

$validationResults->setParent();

setWarningsExist():

$validationResults->setWarningsExist();

Samples of Life in the ActionController

Find allowed Actions

Sometimes you like to know in the controller what actions are allowed:

$frameworkConfiguration = $this
    ->configurationManager
    ->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
$theController = 'Offer';
print_r($frameworkConfiguration['controllerConfiguration'][$theController]['actions']); // array!

Additionally you can check which actions are cacheable:

print_r($frameworkConfiguration['controllerConfiguration'][$theController]['nonCacheableActions']); // array!

Comments

comments powered by Disqus

Previous topic

TYPO3 Extbase Query Methods

Next topic

Solr for docs.typo3.org

Tags

Archives

Languages

Recent Posts

This Page