2017 © Pedro Peláez
 

symfony-bundle froala-editor-bundle

Provides a Froala editor integration for Symfony 2/3/4.

image

kms/froala-editor-bundle

Provides a Froala editor integration for Symfony 2/3/4.

  • Friday, July 20, 2018
  • by samarhxc
  • Repository
  • 8 Watchers
  • 59 Stars
  • 40,520 Installations
  • HTML
  • 1 Dependents
  • 0 Suggesters
  • 19 Forks
  • 6 Open issues
  • 17 Versions
  • 12 % Grown

The README.md

KMSFroalaEditorBundle

Package version Build Status Downloads PHP Version Licence, (*1)

Introduction

This bundle aims to easily integrate & use the Froala editor in Symfony 4.4+/5.0+., (*2)

If you want to use it with Symfony < 4.3, see v2 docs. v2.x is compatible with Symfony 2.x to 4.x, but some deprecations are not fixed and static files are integrated to the bundle., (*3)

There's also a v3 version available compatible with Symfony 4.3+/5.0+ but the form type options are not prefixed with froala_, which is the major reason for a v4 of the bundle., (*4)

The changelogs are available here:, (*5)

Table of Contents

  1. Migration to Froala Editor bundle v4 from v3
  2. Installation
    1. Step 1: Install the bundle using composer
    2. Step 2: Add the bundle to your bundles.php
    3. Step 3: Import routes
    4. Step 4: Load Twig form widget
    5. Step 5: Configure the bundle
      1. Required
      2. Other options
    6. Step 6: Add Froala to your form
    7. Step 7: Install asset files
    8. Step 8: Display editor content
      1. Manually
      2. Using the Twig extension
    9. Step 9: Profiles (custom configurations)
  3. More configuration
    1. Plugins
    2. Concept: Image upload/manager
    3. Concept: File upload
    4. Concept: Autosave
    5. Webpack Encore configuration
  4. TODO
  5. Licence
  6. Contributing

Migration to Froala Editor bundle v4 from v3

It now supports only Symfony 4.4+ & 5.0+., (*6)

If you somehow override/inherit a class from the bundle, be careful as some parameter & return types have been added., (*7)

All form type options must now be prefixed by froala_:, (*8)

// Before
$builder->add('field', FroalaEditorType::class, [
    'toolbarButtons' => [...],
]);

// After
$builder->add('field', FroalaEditorType::class, [
    'froala_toolbarButtons' => [...],
]);

Installation

Step 1: Install the bundle using composer

composer require kms/froala-editor-bundle

Note: if you install the bundle using Symfony Flex & accepted the recipe, you can skip steps 2 to 4., (*9)

Step 2: Add the bundle to your bundles.php

// config/bundles.php
return [
    //..
    KMS\FroalaEditorBundle\KMSFroalaEditorBundle::class => ['all' => true],
];

Step 3: Import routes

# config/routes.yaml 
kms_froala_editor:
    resource: '@KMSFroalaEditorBundle/Resources/config/routing.yml'
    prefix:   /froalaeditor

Step 4: Load Twig form widget

# In config/packages/twig.yaml
twig:
    form_themes:
        - '@KMSFroalaEditor/Form/froala_widget.html.twig'

Step 5: Configure the bundle

Required

First, you have to select your language, other settings are optional (see below)., (*10)

# config/packages/kms_froala_editor.yaml 
kms_froala_editor:
    language: 'nl'

Other options

All Froala options (list provided here) are supported. Just add the option name (prefixed with froala_ if it's in your form type) with your value. If you want to keep Froala default value, don't provide anything in your config file. For options which require an array, provide a value array. For options which require an object, provide a key/value array., (*11)

Note that some options need some plugins (all information provided in the Froala documentation)., (*12)

Example for each option type below:, (*13)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    toolbarInline: true
    tableColors: [ "#FFFFFF", "#FF0000" ]
    saveParams: { "id" : "myEditorField" }

To provide a better integration with Symfony, some custom options are added, see the full list below:, (*14)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # Froala licence number if you want to use a purchased licence.
    serialNumber: "XXXX-XXXX-XXXX"

    # Disable CodeMirror inclusion.
    includeCodeMirror: false

    # Disable Font Awesome inclusion.
    includeFontAwesome: false

    # Disable all bundle javascripts inclusion (not concerning CodeMirror).
    # Usage: if you are using Grunt or other and you want to include yourself all scripts. 
    includeJS: false

    # Disable all bundle CSS inclusion (not concerning Font Awesome nor CodeMirror).
    # Usage: if you are using Grunt or other and you want to include yourself all stylesheets. 
    includeCSS: false

    # Change the froala base path.
    # Useful eg. when you load it from your own public directory.
    # Defaults to "/bundles/kmsfroalaeditor/froala_editor"
    basePath: "/my/custom/path".

    # Custom JS file.
    # Usage: add custom plugins/buttons...
    customJS: "/custom/js/path"

Step 6: Add Froala to your form

Just add a Froala type in your form:, (*15)

use KMS\FroalaEditorBundle\Form\Type\FroalaEditorType;

$builder->add('field', FroalaEditorType::class);

All configuration items can be overridden:, (*16)

$builder->add('field', FroalaEditorType::class, [
    'froala_language'      => 'fr',
    'froala_toolbarInline' => true,
    'froala_tableColors'   => ['#FFFFFF', '#FF0000'],
    'froala_saveParams'    => ['id' => 'myEditorField'],
]);

Step 7: Install asset files

To install the asset files, there is froala:install command that downloads the last version available of Froala Editor and puts it by default in the vendor/kms/froala-editor-bundle/src/Resources/public/froala_editor/ directory:, (*17)

bin/console froala:install

There are a few arguments/options available:, (*18)

  • First (and only) argument (optional): the absolute path where the files will be put after download. Defaults to vendor/kms/froala-editor-bundle/src/Resources/public/froala_editor/.
  • Option tag: the version of Froala that will be installed (eg. v3.0.1). Defaults to master.
  • Option clear (no value expected, disabled by default): Allow the command to clear a previous install if the path already exists.

After you launched the install command, you have to link assets, eg.:, (*19)

bin/console assets:install --symlink public

Step 8: Display editor content

Manually

To preserve the look of the edited HTML outside of the editor you have to include the following CSS files:, (*20)

<!-- CSS rules for styling the element inside the editor such as p, h1, h2, etc. -->
<link href="../css/froala_style.min.css" rel="stylesheet" type="text/css" />

Also, you should make sure that you put the edited content inside an element that has the class fr-view:, (*21)

<div class="fr-view">
    {{ myContentHtml|raw }}
</div>

Using the Twig extension

To use the Twig extension, simply call the display function (note that the front CSS file is not included if the parameter includeCSS is false):, (*22)

{{ froala_display(myContentHtml) }}

Step 9: Profiles (custom configurations)

You can define several configuration profiles that will be reused in your forms, without repeating these configurations., (*23)

When using a profile, the root configuration options will be used & overridden:, (*24)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    heightMax: 400
    attribution: false
    profiles:
        profile_1:
            heightMax: 500
use KMS\FroalaEditorBundle\Form\Type\FroalaEditorType;

$builder->add('field', FroalaEditorType::class, [
    'froala_profile' => 'profile_1',
]);

In this example, profile_1 profile will have these configuration options set:, (*25)

  • heightMax: 500
  • attribution: false

More configuration

Plugins

All Froala plugins are enabled, but if you don't need one of them, you can disable some plugins..., (*26)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # Disable some plugins.
    pluginsDisabled: [ "save", "fullscreen" ]

... or chose only plugins to enable:, (*27)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # Enable only some plugins.
    pluginsEnabled: [ "image", "file" ]

Plugins can be enabled/disabled for each Froala instance by passing the same array in the form builder., (*28)

Concept: Image upload/manager

This bundle provides an integration of the Froala image upload concept to store your images on your own web server (see custom options for configuration like upload folder)., (*29)

If you want to use your own uploader, you can override the configuration (if you need to do that, please explain me why to improve the provided uploader)., (*30)

To provide a better integration with Symfony, some custom options are added, see the full list below:, (*31)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # The image upload folder in your /web directory.
    # Default: "/upload".
    imageUploadFolder: "/my/upload/folder"

    # The image upload URL base.
    # Usage: if you are using URL rewritting for your assets.
    # Default: same value as provided as folder.
    imageUploadPath: "/my/upload/path"

Concept: File upload

This bundle provides an integration of the Froala file upload concept to store your files on your own web server (see custom options for configuration like upload folder)., (*32)

If you want to use your own uploader, you can override the configuration (if you need to do that, please explain me why to improve the provided uploader)., (*33)

To provide a better integration with Symfony, some custom options are added, see the full list below:, (*34)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # The file upload folder in your /web directory.
    # Default: "/upload".
    fileUploadFolder: "/my/upload/folder"

    # The file upload URL base.
    # Usage: if you are using URL rewritting for your assets.
    # Default: same value as provided as folder.
    fileUploadPath: "/my/upload/path"

    # Your public directory, from the root directory.
    # Default: "/public"
    publicDir: "/home"

Concept: Autosave

The Froala autosave concept to automatically request a save action on your server is working, just enter the correct options in your configuration file:, (*35)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    saveURL: "my_save_route"
    saveInterval: 2500
    saveParam: "content"

To provide a better integration with Symfony, some custom options are added, see the full list below:, (*36)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    # Add some parameters to your save URL.
    # Usage: if you need parameters to generate your save action route (see save explaination below).
    # Default: null.
    saveURLParams: { "id" : "myId" }

You can add some parameters in your save route (see custom options)., (*37)

Webpack Encore configuration

If you want to load Froala asset files using npm/yarn and Webpack Encore, here's how to do it:, (*38)

import FroalaEditor from 'froala-editor';
import 'froala-editor/css/froala_editor.pkgd.min.css';
import 'froala-editor/css/froala_style.min.css';

// Load your languages
import 'froala-editor/js/languages/fr.js';

// Load all plugins, or specific ones
import 'froala-editor/js/plugins.pkgd.min.js';
import 'froala-editor/css/plugins.pkgd.min.css';

window.FroalaEditor = FroalaEditor;

function froalaDisplayError(p_editor, error ) {
    alert(`Error ${error.code}: ${error.message}`);
}

window.froalaDisplayError = froalaDisplayError;

Now you can disable Froala bundle CSS/JS inclusion:, (*39)

# config/packages/kms_froala_editor.yaml
kms_froala_editor:
    includeJS: false
    includeCSS: false

Don't forget to import the generated Encore CSS/JS files in your HTML if needed., (*40)

TODO

  • Add some tests

Licence

This bundle provides an integration of the WYSIWYG Froala Editor commercial version. Please read the Froala licence agreement and go to the pricing page if you don't have a licence., (*41)

Contributing

Feel free to contribute, like sending pull requests to add features/tests., (*42)

Note there are a few helpers to maintain code quality, that you can run using these commands:, (*43)

composer cs:dry # Code style check
composer phpstan # Static analysis
vendor/bin/simple-phpunit # Run tests

The Versions

20/07 2018

dev-master

9999999-dev

Provides a Froala editor integration for Symfony 2/3/4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

20/07 2018

v2.8.4

2.8.4.0

Provides a Froala editor integration for Symfony 2/3/4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

03/05 2018

v2.8.1

2.8.1.0

Provides a Froala editor integration for Symfony 2/3/4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

05/02 2018

v2.7.5

2.7.5.0

Provides a Froala editor integration for Symfony 2/3/4.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

19/12 2017

v2.7.3

2.7.3.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

19/12 2017

dev-pr/45

dev-pr/45

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

04/12 2017

v2.7.2

2.7.2.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

02/11 2017

v2.7.1

2.7.1.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

12/10 2017

v2.7.0

2.7.0.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

25/08 2017

v2.6.5

2.6.5.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

15/03 2017

v2.5.1

2.5.1.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

06/02 2017

v2.4.2

2.4.2.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

12/12 2016

v2.4.0

2.4.0.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

15/11 2016

v2.3.5

2.3.5.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

08/08 2016

v2.3.4

2.3.4.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

21/06 2016

v2.3.3

2.3.3.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala

16/02 2016

2.1.0

2.1.0.0

Provides a Froala editor integration for Symfony 2/3.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Stefan Neculai
by Simon Guionniere

editor wysiwyg froala