Introduction to TYPOlight¶
- Introduction to TYPOlight
- Config files and Data Container Array (DCA) files
- The Data Container
- Callbacks and the Data Container
- Examples of Callbacks
- Debugging the Data Container
If we simplify things, TYPOlight is basically structured as follows:
| Config File | Config file that specifies the hierarchy of data structure and thereby which datacontainer to load for which view, e.g. tl_mytable e.g. system/modules/_<mymodule>_/config/config.php |
| Data Container Array (DCA) | An array structure that defines to TL's Backend Class, how to display the data obtained from the DataContainer library (see below) to the user. The DCA has parameters to control the config, listing, operations, edit palettes (and sub-palettes), fields and their evaluation and formatting e.g. system/modules/_<mymodule>_/dca/tl_mytable.php |
| Data Container | A library that provides an interface (edit, list, cut, copy, paste, etc.) with a specific type of stored data, e.g. filesystem, database or other custom data e.g. /system/drivers/DC_Table.php |
| Front-end Modules | A set of classes that retrieve data directly from the database and may then load the DCA dynamically to know how to format the data for the front-end to match that of the back-end, although this is optional e.g. system/modules/_<mymodule>_/ModuleMyModule.php |
Its therefore important to understand the difference between the Data Container (e.g. DC_Table.php) and the Data Container Array (DCA, e.g. dca/tl_news.php). This understanding will greatly improve your ability to develop for TYPOlight.
Config files and Data Container Array (DCA) files¶
In order to practise your understanding of the config files, the DCA (Data Container Array) and its implementation to create a Back-End Module and Front-End Module, you can follow the Tutorial example of a CD Catalog:
- Extension Tutorial - will show you how to develop your own custom CD catalog application
Also, to understand the various parts of the DCA, you can read through its documentation:
- Guide to the Data Container Array - will assist you in the understanding of the DCA and how to create your own custom BE application implementation.
The Data Container¶
The data container is used almost everywhere in the TYPOlight backend. There are three data containers included with TYPOlight, although you are of course free to create/write your own Data Containers and provide them as the dataContainer of your Data Container Array (DCA).
As above, Data Containers are located in system/drivers/ directory, and must start with a name DC_. Most commonly used one is of course the DC_Table, which provides a very elegant mechanism to list, edit and save database table information. Here's a short description of the data containers included in TYPOlight core:
| Table | Default data container, provides access to a database system. |
| File | This is the data container for localconfig.php, where the system settings are stored. |
| Folder | Data container "Folder" provides directory access like the file manager |
Callbacks and the Data Container¶
The data container is often passed to a callback in backend, e.g.
- onload_callback, ondelete_callback
- options_callback, input_field_callback, load_callback, save_callback
Here are the variables you have access to from the passed DataContainer $dc variable in your callback function, where $dc would be your Data Container object. Please note that this is only related/tested with DC_Table.
| $dc->id | int | The id of the affected table row. | |
| $dc->table | string | The table this data container is working on. | This could be tl_settings for a File data container, it does not have to be a database table! |
| $dc->value | mixed | Value of the current field | |
| $dc->field | string | Name of the current field | |
| $dc->inputName | string | Name attribute of the current input field | |
| $dc->palette | string | Name of the current palette | |
| $dc->parentTable | string | Name of the parent table | Applies to DC_Table only. |
| $dc->childTabe | array | Names of one or more child tables | Applies to DC_Table only. |
| $dc->rootIds | mixed | IDs of all root records | Can be an array or single value (string). Applies to DC_Table only. |
Examples of Callbacks¶
Here is an example of a config onload_callback using the Data Container to retrieve data based on the current ID, $dc->id:
1 <?php
2
3 /**
4 * Update the RSS feed
5 * @param object
6 */
7 public function generateFeed(DataContainer $dc)
8 {
9 if (!$dc->id)
10 {
11 return;
12 }
13
14 $this->import('Calendar');
15 $this->Calendar->generateFeed($dc->id);
16 }
17
18 ?>
Here is an example of a field save_callback passing the variable value of the current field, and the Data Container. It then processes the variable value and returns the new value to be saved in the database.
1 <?php
2
3 /**
4 * Deserialize and store the tags
5 * @param object
6 * @param object
7 */
8 public function saveTags($varValue, DataContainer $dc)
9 {
10 $options = deserialize($varValue, true);
11 if (!is_array($options))
12 {
13 return _;
14 }
15
16 return join(',', $options);
17
18 }
19 ?>
Debugging the Data Container¶
While developing applications it may be beneficial to place the following in your code where you need to check the contents of your Data Container:
1 <?php
2
3 print_r($dc);
4
5 ?>