How to utilize extensions for an extension in development?

Discussion forum for Extension Writers regarding Extension Development.
User avatar
Robbie626
Registered User
Posts: 19
Joined: Sun Jan 14, 2018 8:06 pm
Name: Robert Gutierrez

How to utilize extensions for an extension in development?

Post by Robbie626 »

Context: I am planning to use 2 extensions from 2 different authors. One is a Reputation extension and another one is a points extension. This is mainly for the admin panel (settings for the new extension). Unless the new settings built on the new extension go to the existing extensions settings?

For example:

When an event is triggered from the code in my extension, it will add # of reputation points to the user's reputation count with the extension made by author 1.
When a different event is triggered from the code in my extension, it will add # of points to the user's point balance with the extension made by author 2.

Will this integration be part of my extension settings or will it be added respectfully to the other extensions that I need to add to its settings? I think I would be coding it to my extension settings, but need to check if the required extensions are installed to be enabled/function.

I am new to code and trying to process my idea and get quality so I can look through the documentation.
rxu
Extensions Development Team
Posts: 3952
Joined: Wed Oct 25, 2006 12:46 pm
Location: Siberia, Russian Federation

Re: How to utilize extensions for an extension in development?

Post by rxu »

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: Select all

	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: Select all

    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: Select all

	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: Select all

	public function add_page_header_link()
	{
		if ($this->ext_1 && $this->ext_2)
		{
			// Do something
		}
	}
User avatar
Robbie626
Registered User
Posts: 19
Joined: Sun Jan 14, 2018 8:06 pm
Name: Robert Gutierrez

Re: How to utilize extensions for an extension in development?

Post by Robbie626 »

Thank you so much :heart:

Return to “Extension Writers Discussion”