Development BlogACP modules for extensions

Post Reply
User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

ACP modules for extensions

#1

Post by Restless Rancor » October 27th, 2018, 8:17 pm

In the last few days I've attempted to add ACP modules to my extensions.

It's been unnecessarily difficult and I was able to get as far as having a working module if I manually added it in the ACP. Yesterday, after much troubleshooting, I was able to narrow down the potential cause to the migration file not being coded properly, or the language not being correctly loaded and decided to sleep on it and start fresh today.

We're refurnishing the living room and the power has been out all day, so when the solution struck me I couldn't test it so had to tether my laptop to my phone to download the phpBB Skeleton Extension which creates the files for me- there was no need to write them from scratch!

Now that I have a working ACP module I can compare the working code:

Code: Select all

<?php
/**
 *
 * Post Count on Index. An extension for the phpBB Forum Software package.
 *
 * @copyright (c) 2018, Restless Rancor, https://www.restlessrancor.com
 * @license GNU General Public License, version 2 (GPL-2.0)
 *
 */

namespace restlessrancor\postcountonindex\acp;

/**
 * Post Count on Index ACP module.
 */
class main_module
{
	public $page_title;
	public $tpl_name;
	public $u_action;

	public function main($id, $mode)
	{
		global $config, $request, $template, $user;

		$user->add_lang_ext('restlessrancor/postcountonindex', 'common');
		$this->tpl_name = 'acp_demo_body';
		$this->page_title = $user->lang('PCOI_TITLE');
		add_form_key('restlessrancor/postcountonindex');

		if ($request->is_set_post('submit'))
		{
			if (!check_form_key('restlessrancor/postcountonindex'))
			{
				trigger_error('FORM_INVALID', E_USER_WARNING);
			}

			$config->set('acme_demo_goodbye', $request->variable('acme_demo_goodbye', 0));

			trigger_error($user->lang('ACP_DEMO_SETTING_SAVED') . adm_back_link($this->u_action));
		}

		$template->assign_vars(array(
			'U_ACTION'				=> $this->u_action,
			'ACME_DEMO_GOODBYE'		=> $config['acme_demo_goodbye'],
		));
	}
}
with what I originally had:

Code: Select all

<?php

namespace restlessrancor\postcountonindex\acp;

class main_module
{
    public $u_action;
    public $tpl_name;
    public $page_title;

    public function main($id, $mode)
    {
        global $language, $template, $request, $config;

        $this->tpl_name = 'acp_demo_body';
        $this->page_title = $language->lang('PCOI_TITLE');

        add_form_key('acme_demo_settings');

        if ($request->is_set_post('submit'))
        {
            if (!check_form_key('acme_demo_settings'))
            {
                 trigger_error('FORM_INVALID');
            }

            $config->set('acme_demo_goodbye', $request->variable('acme_demo_goodbye', 0));
            trigger_error($language->lang('ACP_DEMO_SETTING_SAVED') . adm_back_link($this->u_action));
        }

        $template->assign_vars(array(
            'ACME_DEMO_GOODBYE' => $config['acme_demo_goodbye'],
            'U_ACTION'          => $this->u_action,
        ));
    }
}
As you can see, the acp/main_module.php file was the culprit and I confirmed my suspicion that the language wasn't being loaded correctly.
This lead me to think the documentation was inaccurate, but it's written in many stages to follow to set up the acme demo extension, so it's likely I've missed specific formatting information from before the modules section.

Now I have a working module I can get to work on adding extension-specific options such as location on index for Post Count on Index and shield color for Attachment Shields.


These aren't the droids you're looking for.

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor