Search code examples
typo3typo3-7.6.xtx-news

extbase action always shows wrong fluid template


I've done several extensions on tx_news:

1) I've added three new actions to newscontroller. first two actions are working as expected. The action eventDetail shows a form. The fluid code for this is

<f:form class="form-horizontal" noCacheHash="true" pageUid="30" action="createApplication" name="newApplication" object="{newApplication}" arguments="{news : newsItem, currentPage: 0, application: newApplication}" enctype="multipart/form-data">
            <f:form.textfield class="form-control" property="name" size="40" required="required" />
            <f:form.hidden name="newsItem" value="{newsItem}" />
            <f:form.submit class="btn btn-primary" value="{f:translate(key:'submitApplyJob')}submit" />
        </f:form>

The action createApplication:

 /**
 * action createApplication
 *
 * @param \FalkRoeder\DatedNews\Domain\Model\Application $newApplication
 * @param \GeorgRinger\News\Domain\Model\News $news news item
 * @return void
 */
public function createApplicationAction(\GeorgRinger\News\Domain\Model\News $news, $currentPage = 1, \FalkRoeder\DatedNews\Domain\Model\Application $newApplication) {

    if (is_null($news)) {
        $previewNewsId = ((int)$this->settings['singleNews'] > 0) ? $this->settings['singleNews'] : 0;
        if ($this->request->hasArgument('news_preview')) {
            $previewNewsId = (int)$this->request->getArgument('news_preview');
        }

        if ($previewNewsId > 0) {
            if ($this->isPreviewOfHiddenRecordsEnabled()) {
                $GLOBALS['TSFE']->showHiddenRecords = true;
                $news = $this->newsRepository->findByUid($previewNewsId, false);
            } else {
                $news = $this->newsRepository->findByUid($previewNewsId);
            }
        }
    }

    if (is_a($news,
            'GeorgRinger\\News\\Domain\\Model\\News') && $this->settings['detail']['checkPidOfNewsRecord']
    ) {
        $news = $this->checkPidOfNewsRecord($news);
    }

    if (is_null($news) && isset($this->settings['detail']['errorHandling'])) {
        $this->handleNoNewsFoundError($this->settings['detail']['errorHandling']);
    }

    $newApplication->setTitle($newsItem->getTitle()." - ".$newApplication->getName() . ', ' . $newApplication->getSurname());

    $this->applicationRepository->add($newApplication);
    $persistenceManager = GeneralUtility::makeInstance("TYPO3\\CMS\\Extbase\\Persistence\\Generic\\PersistenceManager");
    $persistenceManager->persistAll();

    $newsItem->addApplication($newApplication);
    $this->newsRepository->update($newsItem);

    $demand = $this->createDemandObjectFromSettings($this->settings);
    $demand->setActionAndClass(__METHOD__, __CLASS__);

    $assignedValues = [
        'newsItem' => $news,
        'currentPage' => (int)$currentPage,
        'demand' => $demand,
        'newApplication' => $newApplication
    ];

    $assignedValues = $this->emitActionSignal('NewsController', self::SIGNAL_NEWS_CREATEAPPLICATION_ACTION, $assignedValues);
    $this->view->assignMultiple($assignedValues);


}

The problem is, after submitting the form it displays the correct page with pid 30 but it shows the content of the fluid template of the action eventDetail. The application data are not stored in DB.

Second weird thing is, if I remove the argument currentPage from the form, I get a error that the argument is missing because it its needed by definition of the action. That tells me that the correct action is requested.

I do not understand this problem. Just want to have the action executed and to display the fluid template named CreateApplication.html.

If more information needed, I'll add.

UPDATE: If I add an initialize Method for my action, it will be called and the arguments are debugged correctly:

public function initializeCreateApplicationAction(){
    \TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($this->request->getArguments(),'NewsController:139');

}

But still it switches to the wrong fluid template then.


Solution

  • The wong redirect was the result of a validation error. In my application model I set two other fields with validation "notEmpty" but didnt send it with the form. Adding these two fields to the form and give them a value lead to the right result.

    Further Explanation:

    If validation of Domain Model Object fails, the errorAction of class "\TYPO3\CMS\Extbase\Mvc\Controller\ActionController" is called and this forwards to the referring request.