DEPRECATION WARNING

This documentation is not using the current rendering mechanism and is probably outdated. The extension maintainer should switch to the new system. Details on how to use the rendering mechanism can be found here.

Browser Tutorial Hooks (en)

Created:2010-10-13T21:40:33
Changed:2011-03-10T22:24:59
Classification:browser_tut_hooks_en
Description:Handle data from every extension in your extension - supported by hooks of the browser, the TYPO3-Frontend-Engine.
Keywords:forDevelopers, forAdvanced, browser, tutorial, frontend-engine, frontend, engine, hooks
Author:Dirk Wildt - Die Netzmacher
Email:http://wildt.at.die-netzmacher.de
Website:http://die-netzmacher.de
Language:en

img-1 img-2 Browser Tutorial Hooks (en)

Browser Tutorial Hooks (en)

Handle data from every extension in your extension - supported by hooks of the browser, the TYPO3-Frontend-Engine.

img-3

Version: 3.6.3, 2011-03-10

Extension Key: browser_tut_hooks_en - Tutorial for the extension Browser (extkey: browser)

Language: en

Keywords: forDevelopers, forAdvanced, browser, tutorial, frontend- engine, frontend, engine, hooks

Copyright 2010-2011, Dirk Wildt - Die Netzmacher, <http://wildt.at .die-netzmacher.de>

This document is published under the Open Content License

available from http://www.opencontent.org/opl.shtml

The content of this document is related to TYPO3

a GNU/GPL CMS/Framework available from www.typo3.org

Introduction

What does it do?

img-4 Illustration 1: Tutorial in PDF format

This is a tutorial for the extension Browser (extkey: browser). It is

an manual how to use hooks in the browser for your extension

Further Information

Forum

img-5 Illustration 2: The TYPO3-Frontend-Engine Browser Forum

The Browser has its own forum (leading language is German). You are welcome to post any question, bug or snippet code at

TYPO3-Frontend-Engine Browser: Forum http://typo3-browser-forum.de/

Use hooks for your extension!

The Browser enables to publish data in list views and single views. You can access the data of any extension using the browser's hooks.

There are several hooks available.

rows_filter_values

This hook provides the data from any extension as rows for the filters. The rows are consolidated. Consolidation means:

  • you will receive the data like shown in the browser filters (list view only) but without any HTML code and without any TypoScript wrapping
  • the data are localized, if the extension is localized
  • non unique data is removed

rows_filter_options

A hook for manipulation the values for checkboxes, radiobuttons and selectboxes.

rows_list_consolidated

This hook provides the data from any extension as rows. The rows are consolidated. Consolidation means:

  • you will receive the data like shown in the browser list view but without any HTML code and without any TypoScript wrapping
  • the data are localized, if the extension is localized
  • the data are grouped, if the group property of the browser is enabled
  • non unique data is removed

row_single_consolidated

This hook is similar to the hook rows_list_consolidated except that it is triggered by the single view. It may provide data of any extension as elements of the single-view-row. The elements are consolidated. Consolidation means:

  • you will receive the data like shown in the browser's single view but without any HTML code and without any TypoScript wrapping
  • the data is localized if the extension is localized
  • non unique data is removed

BR_TemplateElementsHook

This is a hook to modify elements that are going to be displayed in the next line of a list view or in the next single view. This gives access to the elements of a row before Typoscript processing is done. The row is maintained as $this->_elements and provided in the example function as $obj->_elements .

To modify the browser's output modify this array in place .

BR_TemplateElementsTransformedHook

This is a hook to modify elements that are going to be displayed in the next line of a list view or in the next single view. This gives access to the elements of a row after Typoscript processing has been done. Thus according to the Typoscript the elements may have been modified and links may have been added. The row is maintained as $this->_elementsTransformed and provided in the example function as $obj->_elementsTransformed .

Attention: There is a second array $obj->_elementsBoolSubstitute that holds additional information. You don't need to care about this one if you only modify the values of the elements. But if you add or delete elements you have to treat the array $obj->_elementsBoolSubstitute alike. In other words: the two array alway have to be of same size and they have to use the same keys.

To influence the browsers output modify the arrays in place .

How to use the hooks?

This extension provides sample code. You can use this code for your own extension. You have to adapt the code to your needs.

You need an own extension like this extension.

This is the file tree of browser_tut_hooks_en:

|-- ChangeLog

|-- class.tx_browsertuthooksen.php

|-- doc

| |-- manual.pdf

| `-- manual.sxw

|-- ext_emconf.php

|-- ext_icon.gif

`-- ext_localconf.php

1 directory, 7 files

You have to configure two files:

  • class.tx_browsertuthooksen.php
  • ext_localconf.php

ext_localconf.php

<?php

if (!defined ('TYPO3_MODE')) die ('Access denied.');

if (TYPO3_MODE!='BE')

{

require_once(t3lib_extMgm::extPath($_EXTKEY).'class.tx_browsertuth ooksen.php');

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['rows_filter_val ues'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:' .

'tx_browsertuthooksen->vardump_rows_filter_values';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['rows_filter_opt ions'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:' .

'tx_browsertuthooksen->vardump_rows_filter_options';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['rows_list_conso lidated'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:' .

'tx_browsertuthooksen->vardump_rows';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['row_single_cons olidated'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:' .

'tx_browsertuthooksen->vardump_elements';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['BR_TemplateEleme ntsHook'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:' .

'tx_browsertuthooksen';

$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['browser']['BR_TemplateEleme ntsTransformedHook'][] =

'EXT:browser_tut_hooks_en/class.tx_browsertuthooksen.php:'.

'tx_browsertuthooksen';

}

?>

Comment

In the example above we like to use all six hooks. We have to register it in the ext_localconf.php.

The PHP class file is called class.tx_browsertuthooksen.php (see the file in the next section below). The name of your class depends on the name of your extension.

class.tx_browsertuthooksen.php

The file class.tx_browsertuthooksen.php can be a default php snippet for your own php class.

<?php

require_once(PATH_tslib.'class.tslib_pibase.php');

class tx_browsertuthooksen extends tslib_pibase

{

var $prefixId = 'tx_browsertuthooksen'; // Same as class name

var $extKey = 'browser_tut_hooks_en'; // The extension key.

function BR_TemplateElementsHook($obj)

{

// you may manipulate $obj->_elements in place

if (0)

{

debug($obj->_elements, '$obj->_elements', __LINE__, __FILE__);

}

}

...

function vardump_elements(&$params, &$pObj)

{

// you may manipulate the whole $pObj in place

if (0)

{

var_dump(__METHOD__ . ' (line '. __LINE__ . ')', $pObj->pObj->elements);

}

}

...

}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS' ]['ext/browser_tut_hooks_en/class.tx_browsertuthooksen.php'])

{

include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/browser_ tut_hooks_en/class.tx_browsertuthooksen.php']);

}

?>

Comment

Line 23: We receive some data with our own method vardump_elements.&$params is a reference to the whole browser object. The parameter enables you, to manipulate anyBowser data.$pObj is the Browser object. Because the hook is placed in a class, which is a child of the Browser main class,you have to use the variable $pObj twice: $pObj->$pObj->...If you want to know more about the possibilites of the hook, please read the section"DRS - Development Reporting System" on page 7 below.

Line 26: If you are set 0 to 1, this extension will var_dump the current elements.

DRS - Development Reporting System

The DRS - the Development Reporting System - has the new property "Hooks" from version 3.6.0.

If you have enabled the DRS "Hooks" in the Browser, you will get an report:

  • if any extension doesn't use the hooks or in the other case
  • the name of all extensions, which are using the hook(s).

Credits

Martin Bless

Thanks to Martin Bless ( http://forge.typo3.org/users/1386 ) for the hooks

  • BR_TemplateElementsHook
  • BR_TemplateElementsTransformedHook

Helpful suggestions

If you have helpful suggestions, feel free to publish any question, bug or code snippet on

http://typo3-browser-forum.de/

Posts are welcome in English and German.

Change log

3.6.3 New Features * Added hooks* BR_TemplateElementsHook($obj) - thanks to Martin Bless* BR_TemplateElementsTransformedHook($obj) - thanks to Martin Bless* rows_filter_options Maintenance * Hook rows_filter_consolidated is moved to rows_filter_values

3.6.2 New Feature * 12813: New hook rows_filter_consolidatedafter consolidated rows and before filter

3.6.0 Initial release

Illustration index

Illustration 1: Tutorial in PDF format 3

Illustration 2: The TYPO3-Frontend-Engine Browser Forum 3

12