Getting phpbb_root_path in core.modify_posting_parameters event

Discussion forum for Extension Writers regarding Extension Development.
User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Thu May 02, 2019 11:15 am

Yes, thank you. The solution for my former question was to load my ext language file not only for button handling, but for logfile reading in ACP too ! I did it with additional event service at the very beginning

Code: Select all

function getSubscribedEvents()    {   
        return array(
            'core.user_setup'   =>  'load_language_on_setup', ...
Now all logging is ok. But I still have a similar problem with languages:

Code: Select all

class main_listener implements EventSubscriberInterface
{
    /** @var \phpbb\template\template */
    protected $template;

    /** @var language */
    protected $lang;

    /** @var \phpbb\user */
    protected $user;

...
    public function __construct(
        \phpbb\template\template $template,
        \phpbb\language\language $lang,
        \phpbb\user $user,
        ....
     )    {
        $this->template         = $template;
        $this->lang             = $lang;
        $this->user             = $user;
 
        $user->add_lang_ext('evot/move', 'move');
    }

    static public function getSubscribedEvents()
    {
        return array(
           'core.viewtopic_modify_post_row'    =>  'link_a_button',
           'core.modify_posting_parameters'   =>  'button_pressed',
....
but now my button has the proper language i.e. my own polish shown on the screen and after I press this button the language is the default one i.e. english. Both functions show different results

Code: Select all

    public function link_a_button ($event)     {
        global  $user;
        echo 'link a button ' . $this->user->lang['EMOVE_NIP_TITLE'] . '<br>';
....
    public function button_pressed ($event)     {
        global  $user
        echo ('button pressed ' . $user->lang['EMOVE_NIP_TITLE'] . '<br>');
        $user->setup('viewtopic');
        $user->add_lang_ext('evot/move', 'move');
        echo ('button pressed ' . $user->lang['EMOVE_NIP_TITLE'] . '<br>');
...
$user->setup() nor add_lang_ext won't help much. The title EMOVE_NIP_TITLE is once in polish, twice in english. I guess there is something wrong with variables choice at the class begin.

Do you or somebody else have an idea where to look for an error ?

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

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by david63 » Thu May 02, 2019 11:42 am

Language error messages should go in an info_acp_extensionname.php file so that they will be "picked up" automatically.

You should not be using $lang but should be using the $language object ($lang is depreciated)

You also should not be using globals within a listener, you should be injecting them.
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

User avatar
zlisiecki
Registered User
Posts: 134
Joined: Fri Jan 25, 2002 1:38 pm
Location: Warsaw
Contact:

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by zlisiecki » Fri May 03, 2019 7:51 am

OK, I put all error and log messages in ext/evot/move/language/*/info_acp_move.php . What does it mean "picked up automatically" ? I never used variable $lang and I deleted it now. Do you mean I should not make $user global, but rather inject it from the event structure ?

Another question is the choice of events. What do you think, is it correct ? The first onecore.viewtopic_modify_post_row makes my buttons appear above each post just after [x] [!] ["] . The second one core.modify_posting_parameters is used to, when one of my buttons is pressed.

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1044
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs

Re: Getting phpbb_root_path in core.modify_posting_parameters event

Post by mrgoldy » Fri May 03, 2019 11:01 am

The core code that handles the ACP, automatically checks all extensions that are installed and looks if they have any language files named info_acp_SOMETHING.php. If so, they are automatically added/loaded in all the ACP pages.

What david meant, and perhaps slightly worked it incorrectly, is that you should NOT be using $user->lang['LANG_KEY'];, but use $language->lang('LANG_KEY');. So you should not use global $user in your listener, but instead inject the - '@language' as an argument for the listener in your config/services.yml and then in the constructor like this:

Code: Select all

protected $langauge;

public function __construct(\phpbb\language\language $language)
{
	$this->language	= $language;
}

public function link_a_button ($event)
{
	return $this->language->lang('EMOVE_NIP_TITLE');
}
Moreover, you should not use echo to output things, you should assign them to the template using the template system (\phpbb\template\template).

Code: Select all

$this->template->assign_var('MY_VARIABLE', 'My variable value');

$this->template->assign_vars(array(
	'MY_VAR_2'	=> 'My second variable', 
	'MY_VAR_3'	=> 'My third variable',
));
phpBB Studio / ''Proud member of the Studio"

Post Reply

Return to “Extension Writers Discussion”