FMBbCodeBundle icon indicating copy to clipboard operation
FMBbCodeBundle copied to clipboard

How to use bbcode_clean directly in controller ?

Open QuentinPi opened this issue 10 years ago • 16 comments

Hello, I have a new question about your bundle ! I would like to use the bbcode_clean filter directly in a controller, without using any twig view. I think there is a proper way to call it in a Symfony controller...

QuentinPi avatar Oct 15 '15 14:10 QuentinPi

Get 'fm_bbcode.decoda_manager' service in your controller, and use it like here https://github.com/helios-ag/FMBbCodeBundle/blob/master/Templating/BbcodeExtension.php#L79

helios-ag avatar Oct 16 '15 08:10 helios-ag

Thanks a lot ! It works but I have a problem with the quote and code tags. When I use the bbcode cleaner, it renders nothing !

EDIT : I have also a question about the emoticons, is it possible to configure them with a emoticons.php file like in decoda ? (https://github.com/milesj/decoda/blob/master/src/config/emoticons.php) I read your doc and I call the php file in the config.yml but it doesn't work. I think a .yml is expected. I found a solution for that, by changing the EmoticonHook.php

QuentinPi avatar Oct 19 '15 19:10 QuentinPi

problem with the quote and code tags

If you apply bbcode_clean, inside twig template, did this filter strip code/quote tags from your string?

About second question: this hook expects yml configuration for emoticons file, another way, is to register custom hook, that will look for your emoticons php file

helios-ag avatar Oct 20 '15 16:10 helios-ag

About the first question, yes, the filter strips code and quote tags but also the content. I discovered there is an option in decoda : stripContent, I turn it off and now it's perfect ! But I have a problem with the usage of bbcode_clean in a twig view : how can I pass a filterset string in parameter ?

QuentinPi avatar Oct 20 '15 17:10 QuentinPi

The same way as bbcode_filter(filterSet) -> bbcode_clean(filterSet)

helios-ag avatar Oct 20 '15 18:10 helios-ag

Good ! Your bundle is very powerful ! I have one more question... Does it exist a way to avoid line break with decoda manager ? In the decoda documentation, I see options like "setLineBreaks" or "setMaxNewlines" but it doesn't work in the config.yml...

QuentinPi avatar Oct 21 '15 20:10 QuentinPi

Well, yes. Option setMaxNewlines is not available. But you can make a PR :) Opened issue #125

helios-ag avatar Oct 22 '15 04:10 helios-ag

Hello @QuozPowa

@helios-ag has already responded very well to all questions but I would like to provide some clarifications.

I would like to use the bbcode_clean filter directly in a controller, without using any twig view.

You can also use the fm_bbcode.templating.helper service (ref).

I have also a question about the emoticons, is it possible to configure them with a emoticons.php file like in decoda ? (https://github.com/milesj/decoda/blob/master/src/config/emoticons.php) I read your doc and I call the php file in the config.yml but it doesn't work. I think a .yml is expected. I found a solution for that, by changing the EmoticonHook.php

Both PHP and Yaml configuration files are supported (ref). It uses a delegated loader to use the good one. On PHP format the file must return an FM\BbcodeBundle\Emoticon\EmoticonCollection it is because the emoticons.php file like in Decoda does not work. It is possible to write a loader that support emoticons configuration like in Decoda.

alquerci avatar Oct 26 '15 09:10 alquerci

Well explained @alquerci, thank you!

helios-ag avatar Oct 26 '15 11:10 helios-ag

Yes thank you everyone ! I managed to do what I wanted. Your bundle is very very useful ! :+1:

QuentinPi avatar Oct 28 '15 15:10 QuentinPi

I have again another question ! Do you know if it's possible to get the EntityManager in a filter file ?

QuentinPi avatar Nov 10 '15 10:11 QuentinPi

Can you explain what goal do you plan to achieve with this, and btw what do you mean under 'filter file'?

helios-ag avatar Nov 10 '15 12:11 helios-ag

Sorry, I just realize that it is a decoda file (https://github.com/milesj/decoda/blob/master/src/Decoda/Filter/QuoteFilter.php). Actually, I would like to check the author attribute (quote tag) in the database in order to display a link. I can add my own parse method in this filter but the EntityManager isn't available.

QuentinPi avatar Nov 10 '15 13:11 QuentinPi

Hello @QuozPowa,

There are many ways to achive that the main goal is to extends the Decoda\Filter\QuoteFilter class: * override fm_bbcode.decoda.filter.quote.class configuration * create a new filter for exemple enhanced_quote or what you want, doc

alquerci avatar Nov 20 '15 21:11 alquerci

IMHO injecting EM even in filter isn't a good idea, i think this can be achieved with simpler solution, like providing route to user profile.

helios-ag avatar Nov 21 '15 15:11 helios-ag

Thanks you, I managed to do it :) I meet a new problem with special spaces and emoticons, I will create a new issue !

QuentinPi avatar Aug 07 '16 16:08 QuentinPi