The Extension I am developing stopped working after update to 3.3.11

Get help developing custom BBCodes or request one.
MedicineStorm
Registered User
Posts: 31
Joined: Fri Oct 29, 2021 4:58 pm

The Extension I am developing stopped working after update to 3.3.11

Post by MedicineStorm »

I wrote a custom "hide" bbcode for my board to hide/show spoilers. It was working fine in 3.3.10, but after upgrading to 3.3.11, it causes this error:
angry phpbb 3.3.11 forum wrote:[28-Feb-2024 10:02:37 America/Boise] PHP Fatal error: Uncaught InvalidArgumentException: Filter array (
0 => 'medicinestorm\\custombbcodes\\event\\main_listener',
1 => 'process_tag_hide',
) is neither callable nor an instance of s9e\TextFormatter\Configurator\Items\TagFilter in /forum/vendor/s9e/text-formatter/src/Configurator/Collections/FilterChain.php:67
Stack trace:
#0 /forum/vendor/s9e/text-formatter/src/Configurator/Collections/NormalizedList.php(36): s9e\TextFormatter\Configurator\Collections\FilterChain->normalizeValue(Array)
#1 /forum/ext/medicinestorm/custombbcodes/event/main_listener.php(35): s9e\TextFormatter\Configurator\Collections\NormalizedList->append(Array)
I'm guessing it's because of stricter methodologies in 3.3.11 and/or PHP 8.0+, but I'm not clear what I should be doing differently.
Here is my extension main_listener.php code:

Code: Select all

<?php
namespace medicinestorm\custombbcodes\event;

use Symfony\Component\EventDispatcher\EventSubscriberInterface; 

class main_listener implements EventSubscriberInterface {
	# For including other functions.
	protected $db; // @var phpbb\db\driver\driver_interface
	
	public function __construct(\phpbb\config\config $config 
						,	\phpbb\controller\helper $helper 
						,	\phpbb\template\template $template 
						,	\phpbb\user $user
						,	\phpbb\db\driver\driver_interface $p_db) {

		$this->config 			= $config;
		$this->helper 			= $helper;
		$this->template 		= $template;
		$this->user 			= $user;
		$this->db			= $p_db;
	}
	
    public static function getSubscribedEvents() {
        return [
            'core.text_formatter_s9e_configure_after' => 'configure_bbcodes'
        ];
    }
	
    public function configure_bbcodes($event) {
		# Get the BBCode configurator
		$configurator =	$event['configurator'];

		# process special properties of [Hide] tag
		$configurator->tags['hide']->filterChain
			->append([__CLASS__, 'process_tag_hide']) /* LINE 35: THIS IS THE LINE WHERE THE STACK TRACE SAYS THE ERROR COMES FROM?? */
			->addParameterByName('PARSERVAR.TAGCOUNT.HIDE')
			->addParameterByName('PARSERVAR.PARSERINSTANCE')
			->addParameterByName('PARSERVAR.USERID')
			->addParameterByName('PARSERVAR.POSTID');
    }

	public function process_tag_hide(\s9e\TextFormatter\Parser\Tag $p_tag, 
							   $p_intTagCountHide,
							   $p_intUserID, 
							   $p_intPostID) {
	/*
		Without a unique identifier as the div's id value, clicking any "Hide"/"Show" button on the page will
		toggle only the first [hide] tag, regardless of which [hide]'s button was clicked. Setting the id value
		to a unique number ensures each [hide] button references only its own content.
		The user id and the post id are added to help keep the identifier unique even if the tag count fails.		
	*/
		
		//determine unique identifier
		$strIdentifier = (string)$p_intUserID . '.' . (string)$p_intPostID . '.' . (string)$p_intTagCountHide;
		
		//set the tag's parameter value(s)
		$p_tag->setAttribute('bbcodehidetagid', $strIdentifier);
		return true;
	}
}
Am I missing some step? Should I now be (re)defining the bbcodes differently in the latest PHPBB version?

Just in case it makes a difference, here is the BBCode, as defined in my ACP > Posting > BBCodes:
Usage: [hide={SIMPLETEXT;defaultValue=Click button to toggle hidden content}]{TEXT}[/hide]
HTML replacement:

Code: Select all

<div style="margin-bottom: 1px;">
	<b style="font-size:120%;line-height:116%">{SIMPLETEXT} </b>
	<input 
		value="Show" 
		class="button1" 
		onclick="const element=document.getElementById('bbcode-hide:{@bbcodehidetagid}');
			if(element.style.display!='inline') { 
				element.style.display='inline';
				this.innerText='';
				this.value='Hide';
			} else {
				element.style.display='none';
				this.innerText='';
				this.value='Show';
			}" 
		type="button">
</div>
<div style="border-style:solid;
			border-width:2px;
			border-top-color:#040;
			border-left-color:#040;
			border-right-color:#070;
			border-bottom-color:#070;">
	<div style="display:none;" 
		id="bbcode-hide:{@bbcodehidetagid}">
			{TEXT}
	</div>
</div>
Help line:

Code: Select all

Hidden or "spoiler" text: [hide={optional title text}]{Text to be hidden}[/hide]
E.g.: [hide=Click to see Harry Potter spoilers]Snape kills Dumbledore![/hide]
Last edited by Mick on Fri Mar 01, 2024 8:23 am, edited 1 time in total.
Reason: Solved.
User avatar
JoshyPHP
Code Contributor
Posts: 1290
Joined: Mon Jul 11, 2011 12:28 am

Re: The Extension I am developing stopped working after update to 3.3.11

Post by JoshyPHP »

I've only given a cursory look at your code but I think you need to declare your process_tag_hide() function as static.
I wrote the library that handles markup in phpBB 3.2+.
MedicineStorm
Registered User
Posts: 31
Joined: Fri Oct 29, 2021 4:58 pm

Re: The Extension I am developing stopped working after update to 3.3.11

Post by MedicineStorm »

Hallelujah! That was it. STATIC public function {...

... is the way these are instantiated different in 3.3.11 than it was in 3.3.10? I mean... I should have been using static the whole time, but I didn't notice because it didn't complain until after the update. Thanks, Joshy. That's three I owe you now.

P.S. I thought I had the right place for this question a la Extension Writers Forum, but I guess not since a mod moved it to Custom BBCode Development and Requests. Should I be posting questions about my extension here if they involve BBCodes? Regardless, y'all can put that checkmark on this post.

Return to “Custom BBCode Development and Requests”