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

eZ debug

Timing: Jan 17 2025 23:41:34
Script start
Timing: Jan 17 2025 23:41:34
Module start 'content'
Timing: Jan 17 2025 23:41:35
Module end 'content'
Timing: Jan 17 2025 23:41:35
Script end

Main resources:

Total runtime1.4060 sec
Peak memory usage4,096.0000 KB
Database Queries207

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0074 587.7109180.8438
Module start 'content' 0.00741.2773 768.5547604.5078
Module end 'content' 1.28470.1212 1,373.0625345.0625
Script end 1.4059  1,718.1250 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00420.2968210.0002
Check MTime0.00170.1182210.0001
Mysql Total
Database connection0.00070.048710.0007
Mysqli_queries1.320393.90562070.0064
Looping result0.00210.15062050.0000
Template Total1.371897.620.6859
Template load0.00240.172820.0012
Template processing1.369397.393020.6847
Template load and register function0.00020.011610.0002
states
state_id_array0.00130.089610.0013
state_identifier_array0.00290.203920.0014
Override
Cache load0.00200.1446500.0000
Sytem overhead
Fetch class attribute can translate value0.00190.134630.0006
Fetch class attribute name0.00140.096780.0002
XML
Image XML parsing0.00090.060830.0003
class_abstraction
Instantiating content class attribute0.00000.0018110.0000
General
dbfile0.00310.2202270.0001
String conversion0.00000.000930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

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
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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