[TYPO3-mvc] Multiple instances of same plugin on same page

Hendrik Nadler nadler at simplethings.de
Thu Feb 21 14:32:19 CET 2013


Update: I still have no idea, why the error messages stack(ed) for each plugin instance... Is there a singleton / static storage for them? An Explanation would be highly appreciated.

Anyway, meanwhile I found a more or less better solution, maybe someone wants to use or improve this:

public function initializeOrderAction ()
{
    if ( ! $this->checkFormIdentifier()) {
        $this->forward('index');
    }
}

Before the validation of $testOrder happens in (or before) orderAction, the check wether the submitted form is meant to be processed at this time is implemented. If the uid assigned to the form does not match the uid of the current content element indexAction is called without arguments.  Ugly, but at least it seems to work.

Regards, Hendrik


-----Ursprüngliche Nachricht-----
Von: Hendrik Nadler 
Gesendet: Mittwoch, 20. Februar 2013 10:23
An: TYPO3 v4 MVC project
Betreff: [TYPO3-mvc] Multiple instances of same plugin on same page

Hi List,

i created a little order form with extbase/fluid (TYPO3 4.5) and ran into the good old problem, that multiple instances of it on the same page lead to a... let's call it disaster. The request is mapped to each instance and so on. So I came up with the solution to assign the content element id to the form and check for it in the controller.

The form:

<f:form action="order" object="{testOrder}" name=" testOrder "> <f:form.hidden name="formIdentifier" value="{formIdentifier}" /> ...

The Controller:

/**
 * @param Tx_MyExtension_Domain_Model_TestOrder $testOrder
 * @dontvalidate $testOrder
 */
public function indexAction(Tx_MyExtension_Domain_Model_TestOrder $testOrder = null) {
    if ($this->request->hasArgument('formIdentifier')) {
        $postedFormIdentifier = $this->request->getArgument('formIdentifier'); // the one assigned to the view
        $realFormIdentifier = $this->getFormIdentifier(); // content element uid (tt_content_uid)

        if ($postedFormIdentifier !== $realFormIdentifier) {
            $this->request->setArguments(array());
            $this->request->setErrors(array());

            $testOrder = null;
        }
    }
    
    if ($testOrder === null) {
        /** @var Tx_MyExtension_Domain_Model_TestOrder $testOrder */
        $testOrder = new Tx_MyExtension_Domain_Model_TestOrder();
    }
    
    ...
    
    $this->view->assign('formIdentifier', $this->getFormIdentifier());
    
    ...
}   

This no-tso-beautiful hack seems to work, but the error messages stack (the domain model is validated in orderAction). If you submit the second form, you get double messages, if you submit the third form, you get triple messages and so on. I use ErrorViewHelper and did not find a way to suppress the messages yet.

Tx_Fluid_ViewHelpers_Form_ErrorsViewHelper : $errors = $this->controllerContext->getRequest()->getErrors();

So, my 2 short Questions: 
a) is there a better way to solve this problem? 
b) is it possible to clear the messages in the controller, so I don't get double/triple ones?


Regards, Hendrik
_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list