How to pass parameters to the edit template ?

Author Message

Hakim Bouras

Thursday 30 April 2009 11:19:31 am

Hi,

I have a list of equipments, and the user can filter the list on the color (ie: all the "red" equipments):
- from the list, it possible to edit one of the equipment
- from the edit page, I want to put a <i>Back To The List</i> button, that will go back to the list of equipement, filtered on the color initally chosen by the user

<b>How can the system remember the value of the color filter ?</b>

I tried to pass view_parameters to the URL, but it failed. When I provide such a link:

http://www.site.com/content/edit/5725/(filterColor)/red

it takes me to:

http://www.site.com/content/edit/5725/3/eng-GB

and I loose the (filterMethodType) parameter

I have also tried to set a global variable in my first page, but I cannot read it in the edit template.

Do you have any idea how I could do this (I am using eZ Publish 4.0.3) ?

Thank you for your help,
Hakim

Hakim Bouras

Friday 01 May 2009 1:33:53 am

Do you know if by creating an operator using the following features I should be able to get something working (accross views) ?

$http = eZHTTPTool::instance();
(...)
$http->hasSessionVariable( $filter )
(...)
$operatorValue = $http->sessionVariable( $filter );

Do you may be have an example of such an operator ?

Thank you,
Hakim

Hakim Bouras

Sunday 03 May 2009 10:33:18 pm

Hi,

For those it might help, considering that I do not know if there are any side effects when using the eZHTTPTool as I do (sounds strange that these operators are not natively proposed by eZ Publish).

I created an operator to write session variables :

static function execute( $operatorValue, $namedParameters )  {
   $session_variable_name = $namedParameters['session_variable_name'];
   $session_variable_value = $namedParameters['session_variable_value'];
   $http = eZHTTPTool::instance();
   $http->setSessionVariable( $session_variable_name, $session_variable_value );

   eZDebug::writeNotice("'".$session_variable_value."' stored in session variable: ".$session_variable_name , "Setting Session Variable");

   return;
}

and an operator to read the session variable :

static function execute( $operatorValue, $namedParameters ) {
   $session_variable_name = $namedParameters['session_variable_name'];
   $operatorValue = $namedParameters['session_variable_default_value'];
   $http = eZHTTPTool::instance();
   if( $http->hasSessionVariable( $session_variable_name ) ) {
      $operatorValue = $http->sessionVariable( $session_variable_name );
      eZDebug::writeNotice("'".$operatorValue."' read from session variable: ".$session_variable_name , "Reading Session Variable");
      }
   else {
      eZDebug::writeNotice("Session variable '".$session_variable_name."' not found" , "Reading Session Variable");
   }
   return $operatorValue;
}

Cheers,
Hakim

André R.

Monday 04 May 2009 2:01:54 am

You should return null value if session is not set, so you can figure out if session is set or not.
But I think there are several contributed extensions around that does this (and the exact same way).
If you wrap this up in an extension, remember to label it with a big warning sign about using it in combination with node templates( hint: view cache ).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Hakim Bouras

Monday 04 May 2009 1:09:36 pm

André,

Thank you for your feedback.

When you said :
>>You should return null value if session is not set,
>>so you can figure out if session is set or not.

Are you talking about session variables (not being set when I try to read it) or is there case where user session is not set (ie: anonymous) ?

Hakim

André R.

Monday 04 May 2009 11:52:58 pm

static function execute( $operatorValue, $namedParameters )
{
  $sessionVariableName = $namedParameters['session_variable_name'];
  $operatorValue = $namedParameters['session_variable_default_value'];
  $http = eZHTTPTool::instance();
  if( $http->hasSessionVariable( $sessionVariableName ) )
  {
     $operatorValue = $http->sessionVariable( $sessionVariableName );
  }
  else
  {
    $operatorValue = null;
  }
  return $operatorValue;
}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Hakim Bouras

Tuesday 05 May 2009 1:21:24 am

In fact in my initial code, I retrieve a default value from the parameters, which I return when the session variable does not exist.

 $operatorValue = $namedParameters['session_variable_default_value'];

Thanks for your help,
Hakim

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 19 2025 01:15:58
Script start
Timing: Jan 19 2025 01:15:58
Module start 'layout'
Timing: Jan 19 2025 01:15:58
Module start 'content'
Timing: Jan 19 2025 01:15:59
Module end 'content'
Timing: Jan 19 2025 01:15:59
Script end

Main resources:

Total runtime0.9515 sec
Peak memory usage4,096.0000 KB
Database Queries69

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0049 589.2891152.6406
Module start 'layout' 0.00490.0022 741.929739.4766
Module start 'content' 0.00710.9427 781.4063610.6953
Module end 'content' 0.94980.0016 1,392.101620.1250
Script end 0.9514  1,412.2266 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00310.3295160.0002
Check MTime0.00130.1357160.0001
Mysql Total
Database connection0.00090.099710.0009
Mysqli_queries0.873191.7655690.0127
Looping result0.00070.0761670.0000
Template Total0.919996.720.4600
Template load0.00230.241720.0011
Template processing0.917696.442720.4588
Template load and register function0.00030.026510.0003
states
state_id_array0.00110.112410.0011
state_identifier_array0.00150.156520.0007
Override
Cache load0.00200.2124580.0000
Sytem overhead
Fetch class attribute can translate value0.00060.062520.0003
Fetch class attribute name0.00180.186490.0002
XML
Image XML parsing0.00300.315020.0015
class_abstraction
Instantiating content class attribute0.00000.0035140.0000
General
dbfile0.00330.3416230.0001
String conversion0.00000.000740.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/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
7content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
16content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
7content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 46
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs