/** * Generates the content of an Action template * For some Actions default templates are provided, * other Action templates will just be created emtpy * * @param string $templateRootFolder * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\Action $action * @return string The generated Template code (might be empty) */ public function generateDomainTemplate($templateRootFolder, \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject, \EBT\ExtensionBuilder\Domain\Model\DomainObject\Action $action) { return $this->renderTemplate($templateRootFolder . $action->getName() . '.htmlt', array('domainObject' => $domainObject, 'action' => $action, 'extension' => $this->extension)); }
/** * * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject\Action $action * @param \EBT\ExtensionBuilder\Domain\Model\DomainObject $domainObject * * @return \EBT\ExtensionBuilder\Domain\Model\ClassObject\Method */ protected function buildActionMethod(Model\DomainObject\Action $action, Model\DomainObject $domainObject) { $actionName = $action->getName(); $actionMethodName = $actionName . 'Action'; if ($this->templateClassObject->methodExists($actionMethodName)) { $actionMethod = $this->templateClassObject->getMethod($actionMethodName); } else { $actionMethod = clone $this->templateClassObject->getMethod('genericAction'); $actionMethod->setName($actionMethodName); $actionMethod->setDescription('action ' . $action->getName()); } if (in_array($actionName, array('show', 'edit', 'create', 'update', 'delete'))) { // these actions need a parameter if (in_array($actionName, array('create'))) { $parameterName = 'new' . $domainObject->getName(); } else { $parameterName = \TYPO3\CMS\Core\Utility\GeneralUtility::lcfirst($domainObject->getName()); } $actionMethod->getParameterByPosition(0)->setName($parameterName)->setVarType($domainObject->getFullQualifiedClassName())->setTypeHint($domainObject->getFullQualifiedClassName()); $actionMethod->updateParamTags(); if ($actionName === 'edit') { $actionMethod->setTag('ignorevalidation', '$' . $parameterName); } } $replacements = array('domainObjectRepository' => lcfirst($domainObject->getName()) . 'Repository', 'domainObject' => lcfirst($domainObject->getName()), 'domainObjects' => lcfirst(Inflector::pluralize($domainObject->getName())), 'newDomainObject' => 'new' . $domainObject->getName()); $this->updateMethodBody($actionMethod, $replacements); $this->updateDocComment($actionMethod, $replacements); return $actionMethod; }