Skip to content

Files

Latest commit

 

History

History
50 lines (38 loc) · 1.79 KB

9-using_a_markup_parser.md

File metadata and controls

50 lines (38 loc) · 1.79 KB

Step 9: Using a markup parser

FOSComment bundle allows a developer to implement RawCommentInterface, which will tell the bundle that your comments are to be parsed for a markup language.

You will also need to configure a rawBody field in your database to store the parsed comments.

use FOS\CommentBundle\Model\RawCommentInterface;

class Comment extends BaseComment implements RawCommentInterface
{
    /**
     * @ORM\Column(name="rawBody", type="text", nullable=true)
     * @var string
     */
    protected $rawBody;

    ... also add getter and setter as defined in the RawCommentInterface ...
}

When a comment is added, it is parsed and setRawBody() is called with the raw version of the comment which is then stored in the database and shown when the comment is later rendered.

Any markup language is supported, all you need is a bridging class that implements Markup\ParserInterface and returns the parsed result of a comment in raw html to be displayed on the page.

To set up your own custom markup parser, you are required to define a service that implements the above interface, and to tell FOSCommentBundle about it, adjust the configuration accordingly.

# app/config/config.yml

fos_comment:
    service:
        markup: your_markup_service

That is it!

Return to the index.