Tuesday, October 27, 2009

Customizing a wizard

Learn how to customize wizards created with ZedSeriesWizard

How to define settings with ZedSeriesWizardHelper

note

before reading this be sure to read and understand Getting started with ZedSeriesWizard

ZedSeriesWizardHelper uses it's getSettings() method in order to apply settings to the wizard; this method must return either a string or a ZedSeriesIniConfigWizard instance. If a string is returned ZedSeriesWizard will look for a file named "string_returned".ini.php (e.g. myconfig.ini.php) in the zedseries_lib/wzconfig/ directory and creates a ZedSeriesIniConfigWizard instance reading settings from it.

ZedSeriesIniConfigWizard

This class let us customize the wizard, basically you can:

  • choose to display a header with a logo inside (or even without the logo :D)
  • load css and javascript ; different files can be specified for front end and backend
  • choose whether to show a progress bar during wizard run (i.e. step 1 of 3)
  • specify a different template
  • modify the "next" "previous" and "finish" labels (with i18n support)

tip
please refer to "ZedSeriesWizard Settings" for an explanation of each directive

Returning an object

We override ZedSeriesWizardHelper's getSettings method to change our settings in order to show a progress bar when the wizard is created in front end mode.

<?php 
// ... inside MyFirstWizard class
protected function getSettings() {
// create a new instance and load default settings
$cfg = new ZedSeriesIniConfigWizard('wizard');
// change the display"ProgressBar" entry from the "fe" section
$cfg->fe__displayProgressBar = true;
return $cfg;
}






Load settings from external file




The getSettings() method can also returns a string, in this case we must create a file named "string_returned" inside the zedseries_lib/wzconfig/ directory.




So create the zedseries_lib/wzconfig/myconfig.ini.php and put there the following code:




;<?php exit; ?> 
[fe]
displayProgressBar
= true;



then modify the getSettings() method in this way:




<?php 
protected function getSettings() {
/* the wizard will search for a file named "myconfig.ini.php"
* into the "zedseries_lib/wzconfig/" directory.
*/
return 'myconfig';
}
?>



Taking more control




If you need to:






  • specify the directory from which load the ini files


  • share your settings between different wizards



it's time to extend the ZedSeriesIniConfigWizard class.

So, create your own config class




<?php
class MyConfigClass extends ZedSeriesIniConfigWizard {
protected $strDir = '/system/modules/mymodule/';
}
?>



and modify the getSettings method to reflect the above changes




<?php
protected function getSettings() {
/* this time the wizard will search for a file named "myconfig.ini.php"
* into the "mymodule/wzconfig/" directory.
*/

$cfg = new MyConfigClass('myconfig');
return $cfg;
}
?>



Custom configuration without external file




You can specify your own configuration settings directly into the config class




<?php
class MyConfigClass extends ZedSeriesIniConfigWizard {
public function __construct($filename='wizard') {
// load the filename
parent::__construct($filename);
// apply the changes
$this->fe__displayProgressBar = true;
}
}
?>



Configuration settings




Here is a list of all sections of a config ini file with explanation of each entry. Remember that you can set every entry in your config class just using the syntax




$configInstance->section__entry (e.g. $configInstance->fe__displayProgressBar if you want to change the progress bar behaviour)




be




   these directives will be applied only when TYPOlight runs in backend (TL_MODE is be)



























































useHeaderwhether to show an header before the widgets
titletitle to display in header (ignored if useHeader is false)
logologo to display in header (ignored if useHeader is false)
cssa comma separated list of css files to load
jsa comma separated list of javascript files to load
templatetemplate used for rendering the wizard, its behaviour is the same as TYPOlight module's template



 




fe




   these directives will be applied only when TYPOlight runs in frontend (TL_MODE is fe) and are the same of be ones.




 




wizard




   wizard section contains directives that changes the way ZedSeriesWizard works














showAllWidgets

if true every step displays the widgets beloging of the previous step in disabled state





 




form




in the form section can be specified attributes you want to render in the html tag form, please enter as name=value






e.g.




if you enter




class=stdform
target=_blank



the form will be rendered as




<form class=”stdform” target=”_blank”>




labels




labels section allows you to quickly override default label for buttons
































nextlabel for the “next” button
prevlabel for the “previous” button
finishlabel for the “finish” button

No comments:

Post a Comment