Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TYPO3: Hook after creating or editing page

Tags:

hook

typo3

I'm searching for a hook which is called after page creation or changes on pages like "hide page in nav", "deactivate page" or "move/delete page"

Does someone know of one?

Thanks!

like image 504
FlorianX Avatar asked Nov 23 '12 09:11

FlorianX


People also ask

What is the 'browser title' in TYPO3?

The ' Browser title ' ( title-TAG) will show as a link in the search engine result and also in the browser tab (1). If this field is left empty, TYPO3 will use the page title.

Why doesn't TYPO3 show the company name in the page title?

If this field is left empty, TYPO3 will use the page title. As a standard the TYPO3 will be set to add the company name in the 'Browser title' automatically, but by checking the box ' Title only ' (2), it will only show the information from the 'Browser title' field.

How do I edit the page type properties?

To edit them, you can either right click on the page title, in the page tree, and choose "Edit" (Img. 1.2.1) or you can click the page properties icon above the page content area (Img. 1.2.2). This section will focus on page properties for a Standard page. Read more about other page type properties here.

How do I edit the page settings?

The page settings contains information about metadata, page layout and also has visibility settings. To edit them, you can either right click on the page title, in the page tree, and choose "Edit" (Img. 1.2.1) or you can click the page properties icon above the page content area (Img. 1.2.2).


2 Answers

These Hooks are located in t3lib/class.t3lib_tcemain.php

The following are just some of those:

  • processDatamap_preProcessFieldArray
  • processDatamap_postProcessFieldArray
  • hook_processDatamap_afterDatabaseOperations
  • processDatamap_afterAllOperations

In your case, i think you could use "processDatamap_postProcessFieldArray".

Example how to include it in your ext_localconf.php:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass'][] = 'EXT:your_extension/hooks/class.tx_yourextension_tcemain.php:tx_yourextension_tcemain';

Example class:

<?php
    class tx_yourextension_tcemain {
            function processDatamap_postProcessFieldArray($status, $table, $id, &$fieldArray, &$pObj) {
                if($table == 'pages' && $status =='new') {
                    // do some stuff
                }
            }
    }
?>

With $table, you can check which table is modified. $status allows you to retrieve the current action, for example "new", "update" or "delete".

Example for TYPO3 > 6 with namespaces on another hook:

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/tslib/class.tslib_menu.php']['filterMenuPages']['YourExtension\\Hook\\FilterMenuPages'] = 'EXT:your_extension/Classes/Hook/FilterMenuPages.php:YourExtension\Hook\FilterMenuPages';
like image 61
Shufla Avatar answered Sep 26 '22 14:09

Shufla


For TYPO3 7.6 version (Also Works in 10.4.X as well)

Write following in ext_localconf.php

$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapClass']['extkey'] = 'Vendor\\Extension\\Hook\\TCEmainHook';
$GLOBALS ['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass']['extkey'] = 'Vendor\\Extension\\Hook\\TCEmainHook';

Create hook class /Classes/Hook/TCEmainHook.php, Choose appropriate function from below list

<?php
namespace Vendor\Extension\Hook;

class TCEmainHook {
    public function processCmdmap_preProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processCmdmap_postProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processDatamap_preProcessFieldArray(array &$fieldArray, $table, $id, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processCmdmap_deleteAction($table, $id, $recordToDelete, $recordWasDeleted=NULL, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processDatamap_afterAllOperations(\TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processDatamap_postProcessFieldArray($status, $table, $id, array &$fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
    public function processDatamap_afterDatabaseOperations($status, $table, $id, array $fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {}
}
like image 29
Mihir Bhatt Avatar answered Sep 22 '22 14:09

Mihir Bhatt