How to pass parameters to the edit template ?

How to pass parameters to the edit template ?

Thursday 30 April 2009 11:19:31 am - 6 replies

Modified on Thursday 30 April 2009 11:25:42 am by Hakim Bouras

Author Message

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

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

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