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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 02:03:36
Script start
Timing: Jan 18 2025 02:03:36
Module start 'layout'
Timing: Jan 18 2025 02:03:36
Module start 'content'
Timing: Jan 18 2025 02:03:37
Module end 'content'
Timing: Jan 18 2025 02:03:37
Script end

Main resources:

Total runtime0.8545 sec
Peak memory usage4,096.0000 KB
Database Queries70

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0070 589.0313152.6250
Module start 'layout' 0.00700.0051 741.656339.4531
Module start 'content' 0.01210.8405 781.1094599.4297
Module end 'content' 0.85260.0018 1,380.539120.1641
Script end 0.8544  1,400.7031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00440.5113160.0003
Check MTime0.00160.1922160.0001
Mysql Total
Database connection0.00100.120310.0010
Mysqli_queries0.775090.7041700.0111
Looping result0.00090.1042680.0000
Template Total0.812595.120.4063
Template load0.00270.320820.0014
Template processing0.809894.767520.4049
Template load and register function0.00020.019810.0002
states
state_id_array0.00170.193210.0017
state_identifier_array0.00250.298020.0013
Override
Cache load0.00260.2986500.0001
Sytem overhead
Fetch class attribute can translate value0.00070.083820.0004
Fetch class attribute name0.00170.197680.0002
XML
Image XML parsing0.00070.081420.0003
class_abstraction
Instantiating content class attribute0.00000.0042110.0000
General
dbfile0.00150.1779160.0001
String conversion0.00000.001540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
13content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
3content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 32
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs