Modifying postrow.U_QUOTE

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
Nodashi
Registered User
Posts: 3
Joined: Tue Feb 21, 2017 10:53 am

Modifying postrow.U_QUOTE

Post by Nodashi »

Hi,

i have made an extension that authorize only the author of the topic to post in it.

To made that, i made a listener like this :

Code: Select all

class listener implements EventSubscriberInterface
{
    static public function getSubscribedEvents()
    {
        return array(
            'core.viewtopic_modify_post_action_conditions' => 'viewtopic_modify_post_action_conditions',
        );
    }

    public function viewtopic_modify_post_action_conditions($row)
    {
        global $user, $template;
		
		
		
        if ( $row->get_data()['topic_data']['topic_first_poster_name'] != $user->data['username']) {

            $template->assign_vars(array('S_DISPLAY_REPLY_INFO' => false));
			
        }

    }
}
But i also need to hide the quote button in viewtopic_body.html.

Code: Select all

<!-- IF postrow.U_QUOTE -->
	<li>
		<a href="{postrow.U_QUOTE}" title="{L_REPLY_WITH_QUOTE}" class="button icon-button quote-icon"><span>{L_QUOTE}</span></a>
	</li>
<!-- ENDIF -->
How do i change the postrow.U_QUOTE value to false ?

Best regards

PS : sorry for my bad english, french people you know...
User avatar
kasimi
Former Team Member
Posts: 4900
Joined: Sat Sep 10, 2011 7:12 pm
Location: Germany
Contact:

Re: Modifying postrow.U_QUOTE

Post by kasimi »

You can use the core.viewtopic_modify_post_row event for that:

Code: Select all

$post_row = $event['post_row'];
$post_row['U_QUOTE'] = $event['topic_data']['topic_poster'] == $user->data['user_id'];
$event['post_row'] = $post_row;
By the way, you should use dependency injection instead of using global to access the $user and $template classes.
User avatar
javiexin
Code Contributor
Posts: 1157
Joined: Wed Oct 12, 2011 11:46 pm
Location: Madrid, Spain
Name: Javier
Contact:

Re: Modifying postrow.U_QUOTE

Post by javiexin »

kasimi wrote: Tue Feb 21, 2017 4:24 pm You can use the core.viewtopic_modify_post_row event for that:

Code: Select all

$post_row = $event['post_row'];
$post_row['U_QUOTE'] = $event['topic_data']['topic_poster'] == $user->data['user_id'];
$event['post_row'] = $post_row;
By the way, you should use dependency injection instead of using global to access the $user and $template classes.
Warning, this overwrites the U_QUOTE template variable for all users. To keep it for the topic_poster and remove it from everyone else, try this instead:

Code: Select all

$post_row = $event['post_row'];
$post_row['U_QUOTE'] = ($event['topic_data']['topic_poster'] == $user->data['user_id']) ? $post_row['U_QUOTE'] : '';
$event['post_row'] = $post_row;
If you want to remove it from all, just set it to '' or false (line 2 of kasimi's code, and my modification).
-javiexin
Nodashi
Registered User
Posts: 3
Joined: Tue Feb 21, 2017 10:53 am

Re: Modifying postrow.U_QUOTE

Post by Nodashi »

sorry but something doesn't work i probably failed at something.

here is my code :

Code: Select all

class listener implements EventSubscriberInterface
{
    static public function getSubscribedEvents()
    {
        return array(
            'core.viewtopic_modify_post_action_conditions' => 'viewtopic_modify_post_action_conditions',
	    'core.viewtopic_modify_post_row' => 'viewtopic_modify_quote_action_conditions',
        );
    }

    public function viewtopic_modify_post_action_conditions($row)
    {
        global $user, $template;
		
		
		
        if ($row->get_data()['topic_data']['topic_first_poster_name'] != $user->data['username']) {

            $template->assign_vars(array('S_DISPLAY_REPLY_INFO' => false));
        }

    }
	
	public function viewtopic_modify_quote_action_conditions ($post_row)
	{
		global $user, $template, $event;
		
		$post_row = $event['post_row'];
		$post_row['U_QUOTE'] = $event['topic_data']['topic_poster'] == $user->data['user_id'];
		$event['post_row'] = $post_row;
		
		return $post_row;
	}
}
thanks for your precious help
Nodashi
Registered User
Posts: 3
Joined: Tue Feb 21, 2017 10:53 am

Re: Modifying postrow.U_QUOTE

Post by Nodashi »

Finally found it myself

Code: Select all

public function viewtopic_modify_quote_action_conditions ($event)
	{
		global $user, $template, $post_row;
		
		$post_row = $event['post_row'];
		$post_row['U_QUOTE'] = $event['topic_data']['topic_poster'] == $user->data['user_id'];
		$event['post_row'] = $post_row;
		
	}
thanks for the help
Post Reply

Return to “Extension Writers Discussion”