Table of contents
Hooks make it possible to call certain functions without changing the calling module. The procedure follows this scheme:
RegisterHook
To register a hook, the following function is used in the install function of the underlying module:
$this->app->erp->RegisterHook('hookname_1', 'modulename', 'functionname');
To simplify: If the hook with the name 'hookname_1' is executed by the function 'RunHook', then the 'modulname' 'functionName' has to be called. If a registered hook is no longer needed, it can be deactivated by by passing the fourth parameter of the function 'RegisterHook' as a 0 is passed as the fourth parameter:
$this->app->erp->RegisterHook('hookname_1', 'modulname', 'functionName',0); This call disables the registry.
RunHook
It is also possible to set new hooks via the "RunHook" function:
$this->app->erp->RunHook('hookname_1', 0);
As soon as the function is called, all hooks registered to "hookname_1" are executed in order.
Parameter
It is possible to pass parameters to the functions that are executed via hooks. The second parameter of the function 'Runhook' determines how many parameters are passed.
$this->app->erp->RunHook('hookname_1', 1, $x);
With this hook, all registered functions pass the variable $x as a parameter to all registered functions.
Remove hooks again
To remove hooks from the system that are no longer needed, the function 'RemoveHooks()' can be used:
$this->app->erp->RemoveHook('hookname_1');
Not only the hook 'hookname_1' is removed, but also all registration references to it.
Existing hooks
In the system, hooks are already executed in various places, which can be attached to using "RegisterHook" can be attached to. At the time of writing this article these were:
Module: Hookname cronjobs/amazon.php: 'amazon_cronjob' cronjobs/versandmailsundrueckmeldung.php: 'versanderzeugen_frankieren_hook1' phpwf/plugins/class.yui.php: 'AARLGEditable' phpwf/plugins/class.yui.php: 'AARLGItems_action' phpwf/plugins/class.yui.php: 'AARLGItemsPrice' phpwf/plugins/class.yui.php: 'AARLGItemsLanguage' phpwf/plugins/class.yui.php: 'auftraege_tablesearch' (x2) phpwf/plugins/class.yui.php: 'yui_sortlistadd_draw' phpwf/plugins/class.yui.php: 'yui_sortlistadd_end' phpwf/widgets/easytable.php: 'EasyTableDisplayEditable' (x2) phpwf/widgets/easytable.php: 'EasyTableDisplayEditableClick' www/eproosystem.php: 'eproosystem_end' www/lib/class.erpapi.php: 'ANABREGSRecalculate_1' www/lib/class.erpapi.php: 'ANABREGSRecalculateEnd' www/lib/class.erpapi.php: 'artikelnummerscan' www/lib/class.erpapi.php: 'auftragcheck' www/lib/class.erpapi.php: 'berechnenDeckungsbeitragEnde' www/lib/class.erpapi.php: 'chargenlog_bestand' www/lib/class.erpapi.php: 'document_send_email' www/lib/class.erpapi.php: 'document_SubmitMessageCreated' www/lib/class.erpapi.php: 'documentMask' www/lib/class.erpapi.php: 'DocumentMaskSent' www/lib/class.erpapi.php: 'documentSend_email' www/lib/class.erpapi.php: 'erpapi_delivery_note_output' www/lib/class.erpapi.php: 'erpapi_loadorder_standard_values' www/lib/class.erpapi.php: 'erpapi_loaddelivery_note_standard_values' www/lib/class.erpapi.php: 'ImportAuftrag' www/lib/class.erpapi.php: 'mhdlog_bestand' www/lib/class.erpapi.php: 'paketmarke_abschluss' www/lib/class.erpapi.php: 'parseuservars' www/lib/class.erpapi.php: 'production_explode' www/lib/class.erpapi.php: 'invoice_mail' www/lib/class.erpapi.php: 'shipping_production_franking_hook1' (x3) www/lib/class.erpapi.php: 'versandmail' www/lib/class.erpapi.php: 'WeiterfuehrenAuftragZuLieferschein' www/lib/class.erpapi.php: 'PaymentModeTextPaymentDate' www/lib/dokumente/class.auftrag.php: 'BreifpapierGetAuftragArtikel' www/lib/dokumente/class.auftrag.php: 'BreifpapierGetAuftragEnde' www/lib/dokumente/class.briefpapier.php: 'briefpapier_render_document_hook1' www/lib/dokumente/class.briefpapier.php: 'briefpapier_render_document_hook2' www/lib/documents/class.stationery.php: 'stationery_render_footer_hook1' www/lib/documents/class.stationery.php: 'stationery_render_footer_hook2' www/lib/dispatches/dpd.php: 'dispatches_franking_hook1' (x2) www/lib/versandarten/intraship.php: 'versanderzeugen_frankieren_hook1' (x2) www/lib/shipping_types/logoix.php: 'versanderzeugen_frankieren_hook1' www/lib/shipping_types/other.php: 'versanderzeugen_frankieren_hook1' www/lib/versandarten/spedition.php: 'paketmarke_abschluss' www/lib/shipping_types/ups.php: 'versanderzeugen_frankieren_hook1' www/pages/ajax.php: 'ajax_filter_hook1' www/pages/amazon.php: 'delivery_note_outsource' www/pages/article.php: 'article_ajaxvalues' www/pages/artikel.php: 'article_minidetail_hook1' www/pages/artikel.php: 'article_shopbutton' (x4) www/pages/order.php: 'order_edit_hook1' www/pages/order.php: 'auftraguebersicht_filter' www/pages/bestellvorschlag.php: 'bestellung_einlagern' (order_edit_hook) www/pages/order_proposal_app.php: 'order_proposal_app_calculate' www/pages/order_proposal_app.php: 'order_proposal_app_select' www/pages/commission_consignment_warehouse.php: 'commission_consignment_warehouse_article_tablesearch' www/pages/commission-consignment-stock.php: 'commission-consignment-stock_article'. www/pages/lager.php: 'lager_buchenauslagern_display1' www/pages/lager.php: 'lager_buchenauslagern_mhdlagerbewegung' (x2) www/pages/lagermobil.php: 'lager_buchenauslagern_mhdlagerbewegung' www/pages/delivery_note.php: 'delivery_note_storage' www/pages/onlineshops.php: 'shopexport_create' (x3) www/pages/production.php: 'production_edit' www/pages/production.php: 'production_minidetail' www/pages/production_center.php: 'production_center_final_hook1' www/pages/shopimport.php: 'shopimport' www/pages/shopimport.php: 'shopimport_shopping_basket' www/pages/shopimporter_amazon.php: 'amazon_settings_structure' www/pages/shopimporter_amazon.php: 'shopimporter_amazon_getConfig' www/pages/shopimporter_amazon.php: 'shopimporter_amazon_tabs' www/pages/tax_rules.php: 'tax_rules_berechneerloessteuer_setzen' www/pages/tax_rules.php: 'tax_rules_berechneerloessteuer_uebergeordnet' www/pages/tax-rules.php: 'tax-rules_edit_hook1' www/pages/versanderzeugen.php: 'versanderzeugen_single_complete' www/pages/versanderzeugen.php: 'versanderzeugen_franking' www/pages/versanderzeugen.php: 'versanderzeugen_franking_hook1' www/pages/versanderzeugen.php: 'versanderzeugen_delivery_note_print' www/pages/versanderzeugen.php: 'versanderzeugen_change' www/pages/wareneingang.php: 'wareneingang_display_hook_rma1' (x3) www/pages/wareneingang.php: 'goods_in_warehouse_submit' www/pages/wareneingang.php: 'goods_in_employee_submit'. www/pages/wareneingang.php: 'wareneingang_rma_submit' www/pages/pahlungseingang.php: 'incoming_payments_check_booking' www/pages/payments.php: 'payments_edit_show' (x2) www/pages/time_entry.php: 'time_entry_create_guihook1' (x4) www/widgets/widget.order.php: 'order_itdetail' (x2) www/widgets/widget.order_position.php: 'widget_order_position1' (x2) www/widgets/widget.shopexport.php: 'shopexport_show' www/widgets/widget.shopexport.php: 'shopexport_save'
TableSearch hook
The hook to be used here is:
tablesearch_after with parameters $name and $hookfelder.
$hookfelder is an array of the From array('sql'=>"SELECT ...", 'heading'=>array('ueberschrift1','foobar'))
To register at the Hook in Install or List method, the following applies:
$this->app->erp->RegisterHook('tablesearch_after', 'address', 'AddressTableSearch');
The appropriate method is to be chosen so:
function AdresseTableSearch(&$name,&$hookfelder) { $name = "addresstable"; $hookfields = array('heading'=>array('bla','foobar'); }
Navigation
In addition, it is possible to customize the menu by using hooks. When using navigation hooks, it is not allowed to move from a custom file to the module menu of the inheriting classes. Otherwise, an endless loop will occur during processing and the display will abort with an empty page.
RegisterNavigationHook
In the following the installation in Install() of the module Bsp is shown:
$this->app->erp->RegisterNavigationHook('orderscockpit', 'orderlist', 'sales', 'order cockpit', 'order');
This corresponds to:
$this->app->erp->RegisterNavigationHook('module', 'action', 'mainpoint', 'new navigation title', 'title of existing navigation point');
This will create "index.php?module=auftragscockpit&action=auftraglist" with the name "Order cockpit" in the menu item "Sales" under the field "Order" (optional parameter). parameter) is appended to the menu.
Remove hooks again
If a navigation hook is no longer needed or another underlying function is used, the old navigation hook must be removed. This is possible by removing the corresponding entry from the table "hook_navigation". On the other hand, it can also be done programmatically:
$this->app->erp->RemoveNavigationHook('modulename', 'actionname');
The second parameter is optional. If it is not specified, all hooks associated with the module will be removed.