Book Image

TYPO3 Extension Development

By : Dmitry Dulepov, Adrian Zimmerman
Book Image

TYPO3 Extension Development

By: Dmitry Dulepov, Adrian Zimmerman

Overview of this book

Table of Contents (13 chapters)

Frontend API

This part of the API is used in the Frontend. The number of files is relatively small, but the number of functions is very large. We will review only major functions.


TSFE (historically stands for "TypoScript Frontend") is the main FE class. It is sometimes called "page" object among developers. This class contains methods that determine page ID, parse TypoScript templates, execute templates, process output and cache it. Also, TSFE is responsible for managing FE user object. TSFE is located in the class tslib_fe (exercise: see if you can guess the path to the file name).

Normally, extensions do not call TSFE methods but use some TSFE class attributes. We will describe the most important attributes here:

  • additionalHeaderData

    This is an array where FE plugins can add HTML tags that should appear between <head> and </head> on the page. It is a good practice to start with tx_yourextkey_ prefix. Do not add inline <script> (<script> tag without src attribute) here!

  • additionalJavaScript

    An array where FE plugins may add inline JavaScript, if necessary. It is a good practice to start with tx_yourextkey_ prefix.

  • config

    This is an array. It is the only member with the config key corresponding to the parsed config object from the current TypoScript setup. This array contains merged entries from config and page.config.

  • fe_user

    An object of the class, tslib_feUserAuth, which represents a FE user. The user attribute of this class contains a record from the fe_users table. If FE user is logged in, $GLOBALS['TSFE']->fe_user->user['uid'] will be set, and t3lib_div::testInt will return true for it.

  • id

    This is the current page ID. It is very often used in FE plugins as $GLOBALS['TSFE']->id.

  • lang

    This attribute is the current language code (string value). This is not the same as the ISO language code. It is TYPO3 code to be used with language files. The value default means English. A full list of codes can be found in typo3/sysext/setup/mod/locallang.xml as a set of lang_* entries.

  • page

    This is a record from the pages table that corresponds to the current page. If the page is loaded in a nondefault language, this record will have that language applied (all fields like title or navigation title will be taken from pages_language_overlay and applied to this record).

  • pSetup

    This is a parsed TypoScript setup for the plugin. This is useful in certain cases. For example, you may want to examine the setup of another plugin. It is a parsed TypoScript array.

  • register

    This is an array of registers (see LOAD_REGISTER in TSRef). FE plugins can set registers, and they will be available to other objects on the page (plugins or TypoScript objects from TypoScript setup). The key is register name, value is register value.

  • rootLine

    This is an array of records from the pages table that represents the path to the current page from the root of the website.

  • sys_language_content

    This is a uid field value for the record in the sys_language table. TYPO3 will select content from the tt_content table with sys_language_uid that matches this value.

  • sys_language_uid

    This is a uid field value for the record in the sys_language table. It corresponds to config.sys_language_uid in TypoScript setup.

  • sys_language_mode

    See config.sys_language_mode in TSRef.

Content Objects

Content objects display information on the page. All content object types are described in TSRef and they are implemented by the class named tslib_cObj, which is located in typo3/sysext/cms/tslib/class.tslib_content.php. A quick look at this class reveals familiar names such as TEXT, HTML, USER, or stdWrap.

This class is used very often in FE plugins. It has lots of very well-documented methods. We will describe many of them in due course when we have to use them in our real extension.

Plugin API

Last but not the least in its importance is the tslib_pibase class. This is a base class for the FE plugins. While it is not mandatory to use it, most plugins do because this class provides many helpful methods. We will discuss this class in detail in Chapter 5 of the book. For now, we should know that this class provides the following function groups:

  • Link generation

    These functions allow plugins to create links with plugin parameters in them.

  • Handling of localized labels

    These functions help to retrieve translated labels from the language files.

  • Frontend editing

    These functions help to add FE editing capabilities to plugins (rarely used by plugins).

  • Database queries

    These functions do specialized database queries. Most of them are equivalents of the t3lib_DB functions.

  • Flexform handling functions

    Flexform is a TYPO3 way of having forms inside forms. They are often used for plugin configuration. These functions initialize flexform data and extract information from flexforms.