optionchanges
This is an old revision of the document!
Option Changes Plugin
This plugin exists to make it easy to handle changes to component options (accessed by the “Options” button in the top right corner). Option changes are handled by Joomla and without a change handler, your component does not know they have happened. For some changes, this does not matter. But for others, you need to take some action when an option changes.
To make this easy, install the Component Options Handler plugin and publish it. To make it work for you, add some code to your component install script. It is conveniently done as a method and you can use it with minimal changes:
private function registerWithOptionsHandler(): bool { try { // Get the application $app = Factory::getApplication(); // Register the component with the handler plugin $result = $app->triggerEvent('onRegisterComponent', [ 'com_yourcomponent', 'YourNamespace\\Component\\YourComponent\\Administrator\\Helper\\OptionsHandler', 'handleOptionsChange', true, // Call the method statically 'com_config.component' // Context ]); // Check if registration was successful if (isset($result[0]) && $result[0] === true) { // Registration successful Log::add( 'Successfully registered com_yourcomponent with CompOptionsHandler plugin', Log::INFO, 'com_yourcomponent' ); return true; } else { // Registration failed or no plugin responded Log::add( 'Failed to register com_yourcomponent with CompOptionsHandler plugin. Is the plugin installed and enabled?', Log::WARNING, 'com_yourcomponent' ); return false; } } catch (\Exception $e) { // Log any errors Log::add( 'Error registering com_yourcomponent with CompOptionsHandler plugin: ' . $e->getMessage(), Log::ERROR, 'com_yourcomponent' ); return false; } }
optionchanges.1740497016.txt.gz · Last modified: 2025/02/25 15:23 by admin