SummernoteBundle
What is SummernoteBundle?
Summernotebundle integrates SummerNote WYSIWYG Editor into Symfony form type., (*1)
Status
, (*2)
Requirements
Minimum requirements for this bundle are:
- Symfony 2.3
- Twitter's Bootstrap 3.0
- jQuery 1.9, (*3)
Installation
Add SummernoteBundle to your application's composer.json
file, (*4)
{
"require": {
"solilokiam/summernotebundle": "dev-master"
}
}
Add SummernoteBundle to your application's AppKernel.php
file, (*5)
new Solilokiam\SummernoteBundle\SolilokiamSummernoteBundle()
Add Routing information to your application's routing.yml
:, (*6)
solilokiam_summernote_bundle:
resource: "@SolilokiamSummernoteBundle/Resources/config/routing.xml"
prefix: /summernote
Minimal Configuration
You must determine which object manager are you using. Currently it only supports Doctrine ODM, and doctrine ORM., (*7)
app/config/config.yml
, (*8)
solilokiam_summernote:
db_driver: mongodb #supported orm,mongodb for odm
You must also tell which class is going to inherit the bundle asset class., (*9)
solilokiam_summernote:
asset_class: Acme\DemoBundle\Document\Asset
An example for the asset class can be like this (doctrine odm):, (*10)
<?php
namespace Acme\DemoBundle\Document;
use Solilokiam\SummernoteBundle\Model\SummernoteAsset;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* Class Asset
* @package Acme\DemoBundle\Document
* @MongoDB\Document(collection="assets")
*/
class Asset extends SummernoteAsset
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
...
}
Additional Configuration
Summernote supports some configuration parameters. This parameters can configured application wide in config.yml., (*11)
-
width: This is the width of summernote widget
solilokiam_summernote:
...
width: 500
-
focus: Autofocus the widget.
solilokiam_summernote:
...
focus: true
-
toolbar: Configure toolbars of the widget.Every line in toolbar config is a different button group. You can check available buttons at summernote documentation
solilokiam_summernote:
...
toolbar:
- { name: style, buttons: ['bold', 'italic', 'underline', 'clear'] }
- { name: paragraph, buttons: ['ul', 'ol', 'paragraph']}
Usage
Summernote bundle provides a formtype. This example form uses it:, (*12)
class TestFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
...
$builder->add('test_text', 'summernote');
...
}
...
}
You need also to add some twig tags in your templates to import all CSS and JS needed to make summernote work:, (*13)
...
{% block stylesheets %}
{{ summernote_form_stylesheet(form) }}
{% endblock %}
{% block javascripts %}
{{ summernote_form_javascript(form) }}
{% endblock %}