[Split] BBCode to Dislpay HTML Entities

Get help developing custom BBCodes or request one.
Post Reply
User avatar
kot
Registered User
Posts: 54
Joined: Wed Mar 31, 2010 2:55 am

[Split] BBCode to Dislpay HTML Entities

Post by kot »

JoshyPHP wrote:
Sat Feb 04, 2017 2:53 pm
... You'd need an extension to convert the entity name to the actual character. You could do it in PHP with something like that:

Code: Select all

class listener implements EventSubscriberInterface
{
	static public function getSubscribedEvents()
	{
		return ['core.text_formatter_s9e_configure_after' => 'configure_ent'];
	}
	public function configure_ent($event)
	{
		$event['configurator']->tags['ent']->attributes['content']->filterChain
			->append([__CLASS__, 'decode_ent']);
	}
	static public function decode_ent($name)
	{
		return html_entity_decode('&' . $name . ';', ENT_QUOTES, 'UTF-8');
	}
}
Working on a simple extension of my own, I created a listener similar to the above, but can't make it have any effect. Suppose, I placed the above code into ext/Meow/meow_listener.php -- what do I put into the ext/Meow/config/services.yml? Thank you!
Last edited by Mick on Mon Mar 16, 2020 7:52 am, edited 1 time in total.
Reason: Split from https://www.phpbb.com/community/viewtopic.php?f=438&t=2407656&p=15456861

User avatar
mrgoldy
Development Team Member
Development Team Member
Posts: 1350
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: [Split] BBCode to Dislpay HTML Entities

Post by mrgoldy »

Couple of things that are wrong in your post:
You are missing a vendor (author of the extension) in all your namespaces.

The filename should be identical to the class name,
so either use class listener with listener.php.
or use class meow_listener with meow_listener.php.

It is good practise to put event listeners in the event directory.
So it would become: ext/kot/Meow/event/listener.php.
Make sure you add a namespace kot\meow\event; above the class declaration.

Then in your services.yml file, you'll have to declare the listener.
Give it a service id, the class it is using and tag it as an event.listener.

Code: Select all

services:
    kot.Meow.listener:
        class: kot\meow\event\listener
        tags: [{ name: event.listener }]

User avatar
kot
Registered User
Posts: 54
Joined: Wed Mar 31, 2010 2:55 am

Re: [Split] BBCode to Dislpay HTML Entities

Post by kot »

Thank you. And will this allow me to implement a custom tag [meow] -- invoking my own PHP-function with the text between [meow] and [/meow] and expecting the rendered HTML in the output?

User avatar
mrgoldy
Development Team Member
Development Team Member
Posts: 1350
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: [Split] BBCode to Dislpay HTML Entities

Post by mrgoldy »

I mean... have you tried it already?
It looks like the current code replaces an entity with the counter part. You will have to alter the ent_decode function.
But if you’re writing an extension, please look at how other extensions are handling it and work of that. Trial and error like the rest of us.

Post Reply

Return to “Custom BBCode Development and Requests”