That depends on what would you like to achieve.
F.e. a check can be made inThen the extension will unable to be installed unless both of
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
and then in the listener constructor
and then below in the listener in some subscriber method
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');}
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 }
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;}
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