This is an unlinked fork of https://github.com/AStepanov/RedactorBundle/. True author is Andrey Stepanov, here is only a little bit changed version.
Bundle is destined to add Redactor WYSIWYG editor to your Symfony2 project.
This bundle does not include original Redactor JavaScript library, for using it you should get it from official website http://imperavi.com/redactor/download/
"require": {
...
"kraksoft/redactor-bundle": "dev-master"
...
},
"repositories": [
{
"url": "https://github.com/AStepanov/RedactorBundle.git",
"type": "vcs"
}
],
<?php
public function registerBundles()
{
$bundles = array(
// ...
new Stp\RedactorBundle\StpRedactorBundle(),
);
}
run the command
php app/console assets:install web
# Twig Configuration
twig:
# ...
form:
resources:
- 'StpRedactorBundle:Redactor:fields.html.twig'
stp_redactor:
resource: "@StpRedactorBundle/Controller/"
type: annotation
prefix: /redactor/
RedactorBundle provide opportunity to configure some different options of using (e.g. admin, comments, blog)
Run the command for check all config options
php app/console config:dump-reference stp_redactor
#app/config/config.yml
stp_redactor:
admin:
upload_file:
dir: "%kernel.root_dir%/../web/uploads/content/files"
maxSize: 10M
mimeTypes:
- image/png
- image/jpeg
upload_image:
dir: "%kernel.root_dir%/../web/uploads/content/images"
maxSize: 5M
minWidth: 100
maxWidth: 900
minHeight: 300
maxHeight: 900
role: [ROLE_ADMIN]
blog:
upload_image:
dir: "%kernel.root_dir%/../web/uploads/blog/images"
role: [IS_AUTHENTICATED_FULLY]
comments:
role: [IS_AUTHENTICATED_ANONYMOUSLY]
settings:
lang: en
{# template_with_redactor.html.twig #}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript" src="/path_to_jquery/jquery.js"></script>
<script type="text/javascript" src="/path_to_original_redactor/js/redactor.js"></script>
<script type="text/javascript" src="{{ asset('bundles/stpredactor/js/script.js') }}"></script>
{% endblock %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="/path_to_original_redactor/css/redactor.css" type="text/css" media="screen" />
{% endblock %}
<?php
//BlogPostType.php
namespace Stp\BlogBundle\Form;
use Symfony\Component\Form\FormBuilderInterface,
Symfony\Component\Form\AbstractType;
class BlogPostType extends AbstractType
{
/**
* @param \Symfony\Component\Form\FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
parent::buildForm($builder, $options);
$builder->add('description', 'redactor', array('redactor' => 'blog'));
}
}
{# app/Resources/views/admin_layout.html.twig #}
{% extends 'SonataAdminBundle::standard_layout.html.twig' %}
{% block stylesheets %}
{{ parent() }}
<link rel="stylesheet" href="/path_to_original_redactor/css/redactor.css" type="text/css" media="screen" />
<link rel="stylesheet" href="{{ asset('bundles/stpredactor/css/sonata.css') }}" type="text/css" media="screen" />
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script type="text/javascript" src="/path_to_original_redactor/js/redactor.js"></script>
<script type="text/javascript" src="{{ asset('bundles/stpredactor/js/script.js') }}"></script>
{% endblock %}
# app/config/config.yml
sonata_admin:
templates:
layout: ::admin_layout.html.twig