Login / Status
developer.Resource
Home . Documentation . Document Library . Extension Manuals
Sponsors
hosted by punkt.deTYPO3 and Open Source MagazineAOE Media

1.4. Extending the Tag Cloud

Like nearly any other class in TYPO3, the tx_vgetagcloud_pi1 class can be modified using an XCLASS. However it also provides four hooks (in pi1) for manipulating keywords.

The first hook is used to register methods for extracting keywords from the raw data coming from the database. These methods are used instead of the methods from the tx_vgetagcloud_pi1 class . The second hook enables you to manipulate the full list of keywords before any sorting or capping is applied to it, but after case transformation. The third hook is called just before the keywords are displayed and allows for a list-minute change. The fourth hook comes in at an even later point and makes it possible to manipulate the cObj data just before the rendering is done.

An example class for all hooks is provided in the file hooks/class.tx_vgetagcloud_hook_example.php. For the first hook, the example method shows how to extract data from a flexform field, if such was chosen in the plugin's setup. For the second hook, the example is a function that removes all keywords that are 2-letter long or less. One could also imagine, for example, removing all keywords that appear only once. The example for the third hook introduces a special sorting where keywords are arranged by length (rather useless, but looks nice).

The fourth hook example shows how to link the tag cloud to extension sg_glossary. In the constructor of the  tx_vgetagcloud_hook_example class a list of keywords is loaded from the glossary. Then in the hook the keyword (as stored in tag_keyword) is matched against this list to retrieve the corresponding uid from the tx_sgglossary_entries table. This value is stored in a new field tag_uid. To create the link to the glossary a simple modification is done to the TS setup:

plugin.tx_vgetagcloud_pi1.tagWrap.typolink.additionalParams.dataWrap = &uid={field:tag_uid}

Examples of how to register such functions as hooks is found in the ext_localconf.php file (the lines are commented out so that the example functions are not activated by default).