New Zenner
- Join Date:
- Oct 2008
- Posts:
- 82
- Plugin Contributions:
- 0
Best Practice for Adding JS to Admin Page via Encapsulated Plugin?
Hi folks,
I'm developing an encapsulated plugin for Zen Cart 2.1.x and am trying to find the correct way to add JavaScript to a core admin page, specifically options_name_manager.php. I've run into a load-order issue and would appreciate any insight.
Here is what I have tried so far:
init_script: My first attempt was to use the plugin's admin/includes/auto_loaders/config.my_plugin.php to load an init_script at priority 139. This script failed with a fatal error: Call to undefined function zen_add_admin_js(). This suggests the init_script from an encapsulated plugin runs before the core admin functions are available.
Observer Class: My second attempt was to use an observer class, loaded at priority 200. Diagnostic logging shows the class's __construct() method runs successfully. However, the update() method is never called when listening for either NOTIFY_HTML_HEAD_END or NOTIFY_ADMIN_PAGE_CONTENT_PRE_OUTPUT_OPTIONS_NAME_MANAGER. It seems the observer is instantiated but is not receiving notifications on this specific admin page.
The only method that has worked so far is to directly edit options_name_manager.php to either echo the <script> block or call zen_add_admin_js(). This works, but it is not an encapsulated solution.
My question is: What is the correct, modern, encapsulated way to add JavaScript to a core admin page like this? Is there a known load-order issue with observers on options_name_manager, or is there a different event/hook I should be using?
Thank you for any tips you can offer!
**Case Badges** by Techiant