Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 1746

Extension Writers Discussion • Re: How to utilize extensions for an extension in development?

$
0
0
That depends on what would you like to achieve.
F.e. a check can be made in ext.php within is_enableable() method for 3rd party extensions got enabled, f.e.

Code:

public function is_enableable(){$ext_manager = $this->container->get('ext.manager');return $ext_manager->is_enabled('vendor1/extension1') && $ext_manager->is_enabled('vendor2/extension2');}
Then the extension will unable to be installed unless both of vendor1/extension1 and vendor2/extension2 got enabled first.

Also you can inject 3rd party extensions services as optional dependencies into another extension and then check if they exist f.e. in the listener, and then decide if some code should run. Injecting optional dependency is as easy as f.e. in services.yml (note the question mark)

Code:

    vendor3.extension1.listener:        class: vendor3\extension1\event\main_listener        arguments:            - '@controller.helper'            - '@?vendor1.extension1.main_listener'            - '@?vendor2.extension2.main_listener'        tags:            - { name: event.listener }
and then in the listener constructor

Code:

public function __construct(\phpbb\controller\helper $helper, \vendor1\extension1\event\main_listener $ext_1 = null, \vendor2\extension2\event\main_listener $ext_2 = null){$this->helper = $helper;$this->ext_1 = $ext_1;$this->ext_2 = $ext_2;}
and then below in the listener in some subscriber method

Code:

public function add_page_header_link(){if ($this->ext_1 && $this->ext_2){// Do something}}

Statistics: Posted by rxu — Tue Jul 02, 2024 8:40 am



Viewing all articles
Browse latest Browse all 1746

Trending Articles