Config value in extension

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Config value in extension

Post by bzozoo » Sat Jun 15, 2019 1:15 pm

Hi all

I creatred an new extension:

event/main-listener.php

Code: Select all

<?php
/**
 *
 * bzozoo Mod. An extension for the phpBB Forum Software package.
 *
 * @copyright (c) 2019, bzozoo DEV
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 */

namespace bzozoodev\bzozoomod\event;

/**
 * @ignore
 */
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
 * bzozoo Mod Event listener.
 */
class main_listener implements EventSubscriberInterface
{
	public static function getSubscribedEvents()
	{
		return array(
			'core.user_setup'				=> 'load_language_on_setup',
			'core.common'     => 'global_calls',
		);
	}

	/* @var \phpbb\language\language */
	protected $user;
	protected $template;
	protected $root_path;
	protected $phpEx;
	protected $config;
	protected $language;


	/**
	 * Constructor
	 *
	 * @param \phpbb\language\language	$language	Language object
	 */
	public function __construct(
		\phpbb\user $user,
		\phpbb\config\config $config,
		\phpbb\template\template $template,
		$root_path,
		$phpEx,
		\phpbb\language\language $language)
	{
		$this->user			= $user;
		$this->config		= $config;
		$this->template		= $template;
		$this->root_path	= $root_path;
		$this->phpEx		= $phpEx;
		$this->language		= $language;
	}

	/**
	 * Load common language files during user setup
	 *
	 * @param \phpbb\event\data	$event	Event object
	 */
	public function load_language_on_setup($event)
	{
		$lang_set_ext = $event['lang_set_ext'];
		$lang_set_ext[] = array(
			'ext_name' => 'bzozoodev/bzozoomod',
			'lang_set' => 'common',
		);
		$event['lang_set_ext'] = $lang_set_ext;
		

	}
	
		public function global_calls($event)
	{
		// Assign global template vars.
		$this->template->assign_vars(array(
             'ACTUAL_BB_VERSION'	=> $config['version']
		));
	}


}

config/service.yml

Code: Select all

services:
    bzozoodev.bzozoomod.listener:
        class: bzozoodev\bzozoomod\event\main_listener
        arguments:
            - '@user'
            - '@config'
            - '@template'
            - '%core.root_path%'
            - '%core.php_ext%'
            - '@language'
        tags:
            - { name: event.listener }
I want query actual phpbb version and want print out in an ACTUAL_BB_VERSION template var if extension is enabled
I sitched on phpbb debug and But my result is:
[phpBB Debug] PHP Notice: in file [ROOT]/ext/bzozoodev/bzozoomod/event/main_listener.php on line 82: Undefined variable: config
If I put the 'ACTUAL_BB_VERSION' => $config['version'] code after $this->template->assign_vars(array( ..... into the includes/functions.php, then everything work, the forum prints 3.2.7 where I put the ACTUAL_BB_VERSION code in the template.

I would like to solve this by working with an extension of this own variable.
Why doesn't the extension see $config values?
Thanks, If you can help me

-- Sorry my poor English, It is not my default language ---

User avatar
david63
Registered User
Posts: 16189
Joined: Thu Dec 19, 2002 8:08 am
Location: Lancashire, UK
Name: David Wood
Contact:

Re: Config value in extension

Post by david63 » Sat Jun 15, 2019 1:36 pm

You should be using ACTUAL_BB_VERSION' => $this->config['version']
David
Remember: You only know what you know and - you don't know what you don't know!
My CDB Contributions | How to install an extension
I will not be accepting translations for any of my extensions in Github - please post any translations in the appropriate topic.
No support requests via PM or email as they will be ignored

bzozoo
Registered User
Posts: 24
Joined: Mon Feb 11, 2019 6:33 am

Re: Config value in extension

Post by bzozoo » Sun Jun 16, 2019 1:20 pm

david63 wrote:
Sat Jun 15, 2019 1:36 pm
'ACTUAL_BB_VERSION' => $this->config['version']
Thanks! It works ! :)

Post Reply

Return to “Extension Writers Discussion”