Forums / Developer / How to pass parameters to the edit template ?

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