Extension Hub and Extension Manager Hooks

Skip to end of metadata
Go to start of metadata

With the extension hub hooks it's possible to hook into some actions concerning sharing, updating and enable/disable extensions (bricks and plugins). 

Hooks are quite simple, the hook itself is a simple PHP script without a class or anything else. To use it, just put a file called [HOOKNAME].php into your extension root-directory. For example /plugins/MyPlugin/update.php. 

Structure:

Inside the hook you can access all classes/methods/function, ... as everywhere else in pimcore, you don't have to load anything. (see example below)

Currently there are 4 hooks which you can use:

Update (Hub)

The update hook is called after somebody updates your extension to the latest version. The hook is called directly on the pimcore installation where the extension is installed and the update is performed. 

You as a extension developer can use this hook to make some modifications on the target system, for example to update the database structure for your plugin or to import a class model. 

Inside the update.php the current extension revision is available in the variable $revision.

Example: 

<?php

if($revision == 34) {
   $db = Pimcore_Resource::get();
   $db->exec("CREATE TABLE `myExtension` ( `id` int(11) NOT NULL AUTO_INCREMENT, `someField` varchar(255) NULL DEFAULT NULL, PRIMARY KEY (`id`));");
}

This script will create the database table "myExtension" after you have updated to the revision 34.

Share (Hub)

The concept of the share hook is quite the same as at the update hook. The difference is that this hook is called before you upload/update your extension to the extension hub. 

You can use this hook to make modifications to the extension before you share it.

Example: 

<?php


file_put_contents(PIMCORE_PLUGINS_PATH . "/MyExtension/var/log/debug.log", "");

This example resets the custom log file of the plugin. 

Enable (Manager) (since 1.4.2)

This hook is called when the extension is enabled (not installed) in the Extension Manager. 

You can use this hook for example to create a thumbnail configuration for your area-brick, or something similar. 

Example

<?php


$thumb = new Asset_Image_Thumbnail_Config();
$thumb->setName($this->_getParam("name"));
...
...
$thumb->save();


Disable (Manager) (since 1.4.2)

This hook is called when the extension is disabled in the Extension Manager.

You can use this hook to revert the changes you've made in enable.php

Example

$thumb = Asset_Image_Thumbnail_Config::getByName("myThumbnail");
$thumb->delete();
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.