More exporters can be added to the extension using a simple plugin api.
Warning! The exporter interface is still experimental. Please test your exporters thoroughly before using in production environments!
Creating exporter plugins is very easy. If you follow these steps you won't encounter any problems.
Extending the exporter class
The exporter is based on the class tx_saaddressexport_exporterBase which has to extended by your own exporter class. Furthermore you have to implement the functions:
function name | description |
|---|---|
exporter() | The actual export function which is called by export(). This method does all the exporting and stores it to an internal value. Default is $this->filecontent but not mandatory. You can define own values in your class. See below for returning methods. Return true on success and false on error. |
saveData() | Save the data generated by exporter() to $this->getFilename() Return true on success and false on error. |
getData() | Return the data generated $this->exporter() |
As an example we want to create a plugin for the type XYZ:
The three letter code XYZ will multiple times and will be printed red. It is important that the three letter code is replaced with your code. Otherwise the plugin will fail with a fatal error.
Create the class
Create the file res/exporters/class.tx_saaddressexport_exporterXYZ.php
class tx_saaddressexport_exporterXYZ extends tx_saaddressexport_exporterBase
{var $filecontent;
function exporter()
{//write your exporter code here
$this->filecontent='my exported data';
if ($success)
{return(true);
}
else
{return(false);
}
}
/**
* Save the data to $this->getFilename()
* return true on success false on failure
*
*/
function saveData()
{return(t3lib_div::writeFile($this->getFilename(),$this->getData()));
}
/**
* Return the data exported by your class
*
*/
function getData()
{return($this->filecontent);
}
}
As you see the th code appears in the filename an in the class name. You have to implement the three methods otherwise the exporter will die with a fatal error stating that the method is not implemented. When exporting text files you can copy saveData() and getData() you only have to change them when exporting to binary data.
Editing the xml file
Open the file res/plugins.xml in an editor.
<phparray>
<numIndex index="0" type="array">
<name>CSV</name>
<ext>csv</ext>
</numIndex>
<numIndex index="1" type="array">
<name>XML</name>
<ext>xml</ext>
</numIndex>
<numIndex index="2" type="array">
<name>HTML</name>
<ext>html</ext>
</numIndex>
<numIndex index="3" type="array">
<name>XYZ</name>
<ext>zyx</ext>
</numIndex>
</phparray>
Add a new section to the xml file. Be sure to increment index. This is very important! Set name to the three letter code and ext to the extension of your export file.
Add the plugin to the backend
At last we must add the plugin to the list of exporters in backend. This can be a bit confusing and can lead to errors in the backend. So make a backup of your files before editing them!
Open locallang_db.php in an editor and search for “tx_saaddressexport_xportprofile.xportfunction.I”. You will find multiple entries which are numbered. The last entry's number should (index of your plugin)-1 (see above – Editing the xml file) copy this line, change the number to your index and change the text appropriately. This file contains Translations for every language, insert the translation for every language you know as described.
Now open tca.php and locate sa_addressexport/locallang_db.php:tx_saaddressexport_xportprofile.xportfunction.I. This has to end with the same number as above. Copy the complete line and change the numbers the same way as you did above.
Now you are done and you can use your plugin.
Reference
Reference (TypoScript)
Property: | Data type: | Description: | Default: |
|---|---|---|---|
allWrap /+stdWrap | wrap | Wraps the whole item |