Cannot correctly use viewtopic_body_contact_fields_after.html event.

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Feneck91
Registered User
Posts: 115
Joined: Mon May 20, 2013 9:47 am
Name: Stéphane Château
Contact:

Cannot correctly use viewtopic_body_contact_fields_after.html event.

Post by Feneck91 »

Hello ladies and gentleman...

To write my extension Introduciator I need to put a button under "contact" in viewtopic page (and elsewhere too).
My repo : https://github.com/Feneck91/Introduciator

So my listener use event 'core.viewtopic_modify_post_data' and 'core.viewtopic_post_row_after'.
On core.viewtopic_modify_post_data, just read all users present in page and get introduciator information about each user :

Code: Select all

	public function on_viewtopic_modify_post_data($event)
	{
		if ($this->introduciator_helper->is_introduciator_allowed())
		{
			$user_cache = $event['user_cache'];

			foreach ($event['user_cache'] as $user_id => $user_info)
			{
				$user_cache[$user_id]['datas_introduciator'] = $this->introduciator_helper->introduciator_get_user_infos($user_id, $user_info['username']);
			}

			$event['user_cache'] = $user_cache;
		}
	}
This seem to work well.

The problem is when I want to put information to the template:

Code: Select all

	public function on_viewtopic_post_row_after($event)
	{
		$data_introduciator = $event['user_poster_data']['datas_introduciator'];

		$this->template->assign_block_vars('postrow', array(
				'S_INTRODUCIATOR_DISPLAY'	=> $data_introduciator['display'],
				'U_INTRODUCIATOR_URL'		=> $data_introduciator['url'],
				'T_INTRODUCIATOR_TEXT'		=> $data_introduciator['text'],
				'T_INTRODUCIATOR_CLASS'		=> $data_introduciator['class'],
			));
	}
I use 'postrow' in the html template but the code kill some items in the page and all of these information are not displayed.

I think assign_block_vars('postrow', .. overwrite 'postrow' info. Or not…
I just try to add info to 'postrow' to be able to use into my template page.

Code: Select all

{% INCLUDECSS '@feneck91_introduciator/introduciator.css' %}

<!-- IF postrow.S_INTRODUCIATOR_DISPLAY -->
	<div class="{postrow.T_INTRODUCIATOR_CLASS}" title="{postrow.T_INTRODUCIATOR_TEXT}">
	<!-- IF postrow.U_INTRODUCIATOR_URL -->
		<a href="{postrow.U_INTRODUCIATOR_URL}" alt="{L_INTRODUCIATOR_MEMBER_INTRODUCTION}" title="{postrow.T_INTRODUCIATOR_TEXT}">
	<!-- ENDIF -->
	<span>{L_INTRODUCIATOR_MEMBER_INTRODUCTION}</span>
	<!-- IF postrow.U_INTRODUCIATOR_URL -->
		</a>
	<!-- ENDIF -->
	</div>
<!-- ENDIF -->
Any idea for "how to do" ?
Thanks.
User avatar
mrgoldy
Former Team Member
Posts: 1394
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Cannot correctly use viewtopic_body_contact_fields_after.html event.

Post by mrgoldy »

You probably should not assign them yourself but have to merge the array back into the event.
I am guessing you are using the core.viewtopic_modify_post_row event.
So then you'll have to do something like this:

Code: Select all

$post_row = $event['post_row'];
$data_introduciator = $event['user_poster_data']['datas_introduciator'];

$post_row['S_INTRODUCIATOR_DISPLAY'] = $data_introduciator['display'];
// etc

$event['post_row'] = $post_row;
Or an alternative way of coding would be:

Code: Select all

$data_introduciator = $event['user_poster_data']['datas_introduciator'];

$event['post_row'] = array_merge($event['post_row'], array(
	'S_INTRODUCIATOR_DISPLAY'	=> $data_introduciator['display'],
	// etc..
));
phpBB Studio / Member of the Studio

Contributing: You can do it too! Including testing Pull Requests (PR).
phpBB Development and Testing made easy.
User avatar
Feneck91
Registered User
Posts: 115
Joined: Mon May 20, 2013 9:47 am
Name: Stéphane Château
Contact:

Re: Cannot correctly use viewtopic_body_contact_fields_after.html event.

Post by Feneck91 »

Finally, I have done:

Code: Select all

	public function on_viewtopic_modify_post_row($event)
	{
		if ($this->introduciator_helper->is_introduciator_allowed())
		{
			// Prepare data to display link to suer's introduce
			$data_introduciator = $event['user_poster_data']['datas_introduciator'];
			$event['post_row'] += array(
				'S_INTRODUCIATOR_DISPLAY'	=> $data_introduciator['display'],
				'U_INTRODUCIATOR_URL'		=> $data_introduciator['url'],
				'T_INTRODUCIATOR_TEXT'		=> $data_introduciator['text'],
				'T_INTRODUCIATOR_CLASS'		=> $data_introduciator['class'],
			);
		}
	}
Post Reply

Return to “Extension Writers Discussion”