Pimcore plugins should extend Pimcore_API_Plugin_Abstract and must implement Pimcore_API_Plugin_Interface. This means a plugin must implement the install, uninstall and isInstalled static methods specified in the interface. The install method can be used to create database tables and do other initial tasks. The uninstall method should make sure to undo all these things. Moreover it can override the readyForInstall method (since v1.0.5 build 110). This is the right place to check for requirements such as minimum pimcore version or read/write permissions on the filesystem. If this method returns false, the plugin cannot be installed via the pimcore admin.
PHP Hooks
A plugin can overwrite the following methods which are called for each registered plugin upon certain hooks:
/** * * Hook called after an asset was added * * @param Asset $asset */ public function postAddAsset(Asset $asset){} /** * Hook called before an asset is deleted * * @param Asset $asset */ public function preDeleteAsset(Asset $asset){} /** * Hook called after an asset is updated * * @param Asset $asset */ public function postUpdateAsset(Asset $asset){} /** * * Hook called after a document was added * * @param Document $document */ public function postAddDocument(Document $document){} /** * Hook called before a document is deleted * * @param Document $document */ public function preDeleteDocument(Document $document){} /** * Hook called before a document is updated * * @param Document $document */ public function preUpdateDocument(Document $document){} /** * Hook called after a document was updated * * @param Document $document */ public function postUpdateDocument(Document $document){} /** * Hook after an object was is added * * @param Object_Abstract $object */ public function postAddObject(Object_Abstract $object){} /** * Hook called before an object is deleted * * @param Object_Abstract $object */ public function preDeleteObject(Object_Abstract $object){} /** * Hook called before an object is updated * * @param Object_Abstract $object */ public function preUpdateObject(Object_Abstract $object){} /** * Hook called after an object was updated * * @param Object_Abstract $object */ public function postUpdateObject(Object_Abstract $object){} /** * Hook called when login in pimcore is about to fail. Must return * a valid pimcore User for successful authentication or null for failure. * * @param string $username username provided in login credentials * @param string $pasword password provided in login credentials * @return User authenticated user or null if login shall fail */ public function authenticateUser($username, $password) {} /** * Hook called when the user logs out * * @param User $user */ public function preLogoutUser(User $user){} /** * * Calls preDispatch of all registered plugins and system modules */ public function preDispatch() {}
User Authentication by Plugin (since pimcore 1.3.2)
If the pimcore user authentication is about to fail, the plugin hook "authenticateUser" is called for all registered plugins until a plugin returns a valid user. With this hook it is possible to implement pimcore user authenticaition by a plugin. However, the plugin must return a valid pimcore user being active and having an ID. Once authentication was successful, no further plugins are called with this hook.
i18n
If a plugin requires its own i18n texts in pimcore admin user interface, it should override the getTranslationFile method contained in Pimcore_API_Plugin_Abstract. This method receives the current language as parameter and must return the path to the according texts file relative to the plugin directory. E.g. something like ”/Testplugin/texts/en.csv”. The texts file must be a .csv file in which translations are specified by the translation key in the first column and the text in the second column. Column separator: ',' text identifier: '”'
/** * * @param string $language * @return string $languageFile for the specified language relative to plugin directory */ function getTranslationFile($language){ return null; }
Plugin Installation and Deinstallation in pimcore UI
When a plugin is installed/uninstalled in the pimcore admin user interface, the frontend component might need the following information from the plugin. If a plugin does not have a user interface component, these abstract methods can be ignored, and do not need to be overridden. More information on installing and uninstalling a plugin with UI components, is provided in plugin user interface development.
public static function getJsClassName(){ return ""; } public static function needsReloadAfterInstall(){ return false; }
Plugin State
Since pimcore 1.1.0 each plugin has the possiblity to issue a status message which is displayed in pimcore plugin settings. To accomplish that, the getPluginState() Method of Pimcore_API_Plugin_Abstract needs to be overridden in the plugin class.
Local storage for your plugin (dynamic files)
Sometimes a plugin needs some HDD - space to put logfiles or some other dynamic files on it.
Please put this files into /website/var/plugins/YOUR_PLUGIN_NAME/
Comments (1)
Jun 23, 2011
Sandeep Narwal says:
how do i add new module in Admin, say my system has 1000 users. I cannot show th...how do i add new module in Admin, say my system has 1000 users. I cannot show them all in Tree. How do i show them in a grid in admin? Can i do it via plugin?
Thanks.