Forums / Developer / module->redirectTo problem

module->redirectTo problem

Author Message

Marcel Marnet

Monday 27 June 2011 3:02:35 am

Hello everybody,

i got a problem by redirecting content/edit after publising.

My own module /mymodule/myview/objectID runs the "edit" view of the "content" module and shows me the content/edit interface, with its input-fields, buttons, ...

When i hit the "publish"-button, i call my module and run content/edit with the currentAction "Publish" again but the redirect to the value of the hidden input field "RedirectURIAfterPublish" doesnt work. It always redirects me to /mymodule/myview/objectID. (Publishing of my object is successful!)

I already checked the handling of my redirect-session-variable. The function computeRedirect inside edit.php calls the function $module->redirectTo() correctly.

Does anyone have any suggestions?

Thanks in advance!

Marcel

Nicolas Pastorino

Wednesday 29 June 2011 6:19:54 am

Hi Marcel, 

If you are running the content/edit view from your custom module's code, through a redirection (in this the case ? ) once the form was submitted, post data is not forwarded. The computeRedirect(...) method can then rely on the session variable called 'RedirectURIAfterPublish'. An idea can be to set this variable in session from your custom code, based on the according value posted, before running the content/edit view, and un-setting it after the execution.

Let us know how things go,
Cheers, 

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Marcel Marnet

Wednesday 29 June 2011 6:54:02 am

Hi Nicolas,

i don't run the content/edit module through a redirection. I run the view trough the $module->run(...); function. So the post variables are deliviered correctly to the content/edit view, also the "RedirectURIAfterPublish"-session variable is set correctly.

the following statements inside the computeRedirect-function are called with my custom redirect-uri.

if ( $http->hasPostVariable( 'RedirectURIAfterPublish' )  && !$hasRedirected )
{
        $uri = $http->postVariable( 'RedirectURIAfterPublish' );
        $module->redirectTo( $uri );
        $hasRedirected = true;
 }

but after the content/edit is proceeded, i got redirected to /mymodule/myview/objectID instead of to the value of my RedirectURIAfterPublish-input field.

Thanks!

Marcel

Nicolas Pastorino

Thursday 30 June 2011 4:05:30 am

Hi Marcel, 

Could you post your custom module code (at least the concerned part) ?
That might help us shed some light on this obscure behavior.

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Marcel Marnet

Thursday 30 June 2011 5:22:27 am

Hi Nicolas,

here is the concerned code:

         $module = eZModule::findModule( 'content' );
        if ( !$module instanceof eZModule ) echo "TODO: error handling";
        $moduleViews = $module->attribute('views');        
        if ( !isset( $moduleViews[ $action ] ) ) echo "TODO: error handling";
       
        $object         = eZContentObject::fetch($objectID);
        if(!$object) echo "TODO: error handling";
        if(!$object->canEdit()) echo "TODO: error handling";
        
        $currentVersion = $object->attribute('current_version')+1;
        //$currentVersion = "f";
        $currentLanguage= $object->currentLanguage();
        $mainNodeID     = $object->attribute('main_node_id');
        $objectArray = array(     "object"             => $object,
                                "ObjectID"            => $objectID,
                                "MainNodeID"         => $mainNodeID,
                                "currentVersion"    => $currentVersion,
                                "currentLanguage"    => $currentLanguage
        );
        $versionID = $currentVersion;
        if( !$http->hasPostVariable( 'CancelDraftButton' ) && !$http->hasPostVariable( 'PublishButton' ) )
            {
                $cleanUpStatuses = array(eZContentObjectVersion::STATUS_INTERNAL_DRAFT, eZContentObjectVersion::STATUS_DRAFT);
                $cleanUpResult = eZContentObjectVersion::removeVersions($cleanUpStatuses);
                $newVersion = $object->createNewVersion();
                $newVersionID = $newVersion->attribute("version");
                $versionID = $newVersionID;
            }
        $editParameters = array( $objectArray['ObjectID'], $versionID, $objectArray['currentLanguage'] );
        if( $thisModule->currentAction() )
            {
                $module->setCurrentAction($thisModule->currentAction());    
            }
        $moduleResult = $module->run( $action, $editParameters, false, array() );
        echo $moduleResult["content"];

the last 2 rows are the most important ones.

Regards,

Marcel

Nicolas Pastorino

Thursday 30 June 2011 5:58:51 am

Hello again Marcel, 

Side-remark : It appears that this code is reproducing features (access right check, version increment) served by action.php/edit.php, whilst not adding real customization (from what i can see, maybe not all the code was pasted). A more maintainable alternative is to use a custom edit handler, run on top of the normal code for editing content. More information on this : http://serwatka.net/blog/do_you_need_action.

Concerning your module : i believe that echo'ing the result of the 'content' module's view is the reason why no redirection occurs. Usually modules neither echo, nor return anything , they just populate the various entries in the $moduleResult variable. Have you tried removing the last "echo" line ?

Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Nicolas Pastorino

Tuesday 05 July 2011 2:03:06 am

Edit to last message : returning $moduleResult should to the deal.

Let us know Marcel,
Cheers, 

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye