Development BlogGlobal enable/disable configuration

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

Global enable/disable configuration


Post by Restless Rancor » October 28th, 2018, 12:54 pm

I've spent today adding a global enable/disable setting to User's Post Count on Index.

I wasn't able to find any documentation on this, so took a look at multiple different extensions which have such a function to see how they are working.

I was eventually able to get it working in the ACP module:

Code: Select all

if ($request->is_set_post('submit'))
	if (!check_form_key($form_name))
		trigger_error('FORM_INVALID', E_USER_WARNING);

	$this->config->set('pcoi_enable', $this->request->variable('pcoi_enable', 0));
	// Add to admin log
	$phpbb_log->add('admin', $user->data['user_id'], $user->ip, 'PCOI_UPDATED');
	trigger_error($user->lang('PCOI_SAVED') . adm_back_link($this->u_action));

// Assign to global template.
	'PCOI_ENABLE'		=> (!empty($this->config['pcoi_enable'])) ? true : false,
	'U_ACTION'			=> $this->u_action,
...using a {% if PCOI_ENABLE %} in adm/style/acp_pcoi_body.html to see if was working, but it took a while to figure out how to get it assigned to the global template variables for use outside of that page.

Adding it to the listener was the trick:

Code: Select all

public function pcoi_header()
	$this->language->add_lang('common', 'restlessrancor/postcountonindex'); 
	$posts = (int) $this->user->data['user_posts'];		
		'S_USER_ID'		=> $this->user->data['user_id'],
		'USER_POST_COUNT' => $this->language->lang('USER_POSTS', $posts),
		'S_PCOI_ENABLE'	=> $this->config['pcoi_enable'] ? true : false,
I can now use the same methods to add location-specific settings.

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

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor