eZ Community » Forums » Developer » module->redirectTo problem
expandshrink

module->redirectTo problem

module->redirectTo problem

Monday 27 June 2011 12:02:35 pm - 6 replies

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

Wednesday 29 June 2011 3:19:54 pm

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, 

Wednesday 29 June 2011 3:54:02 pm

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

Modified on Wednesday 29 June 2011 3:54:38 pm by Marcel Marnet

Thursday 30 June 2011 1:05:30 pm

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,

Thursday 30 June 2011 2:22:27 pm

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

Modified on Thursday 30 June 2011 2:23:41 pm by Marcel Marnet

Thursday 30 June 2011 2:58:51 pm

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,

Tuesday 05 July 2011 11:03:06 am

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

Let us know Marcel,
Cheers, 

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from