Download the PHP package monsieurbiz/sylius-rich-editor-plugin without Composer
On this page you can find all versions of the php package monsieurbiz/sylius-rich-editor-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download monsieurbiz/sylius-rich-editor-plugin
More information about monsieurbiz/sylius-rich-editor-plugin
Files in monsieurbiz/sylius-rich-editor-plugin
Package sylius-rich-editor-plugin
Short Description A Rich Editor plugin for Sylius.
License MIT
Informations about the package sylius-rich-editor-plugin
Sylius Rich Editor
This plugin adds a rich editor on the fields you want. Now you can manage your content very easily!
Compatibility
Sylius Version | PHP Version |
---|---|
1.11 | 8.0 - 8.1 |
1.12 | 8.1 - 8.2 |
1.13 | 8.1 - 8.2 |
Installation
Require the plugin
If you want to use our recipes, you can configure your composer.json by running:
For the installation without flex, follow these additional steps
Change your `config/bundles.php` file to add the line for the plugin : Then create the config file in `config/packages/monsieurbiz_sylius_rich_editor_plugin.yaml` : Finally import the routes in `config/routes/monsieurbiz_sylius_rich_editor_plugin.yaml` :
Correct Twig\Extra\Intl\IntlExtension
conflict
If the recipe did not comment it, update the file config/packages/twig.yaml
to comment or remove the IntlExtension
declaration :
Install the assets
If the auto-script
is not in your composer.json
project, you can install the assets with the following command:
Use it with the Sylius Media Manager
You don't need to do something, everything is compatible.
If you used the rich editor before using the media manager, you need to override the form theme of the media manager plugin :
Use the Rich Editor
Update your form type
To make a field use the rich editor, you must use the RichEditorType
type for it.
We have an example of implementation in the file for the test application.
If your field has some data already, like some previous text before installing this plugin, then we will convert it for you as an HTML Element which contains… HTML.
This way you will be able to use our plugin right away without risking any data lost!
To make it clear: to have rich editor for original admin fields, like Product description, Taxon desription etc. you have to update each form type by an extension as the example shows above.
Call twig render
To display the content of the rich editor field you must call the twig filter:
You can see an example in the file for the test application
Custom rendering of elements
You can also render your elements with some custom DOM around that. To do so, you have access to a twig filter that gives you the elements list :
And then you can either render them all :
Or one by one :
Filter the elements
If you want to filter the elements which are available for your field, you can use the tags
option when you build your form.
As example:
In that example, all Ui Elements with the tag default
will be excluded, then the Ui Elements with the tag product
will be included.
Don't worry, you can add this filter afterwards, we won't remove the already present Ui Elements of your field. But we
won't allow to add more if they don't have one of the allowed tags!
Order matters
The order of the tags matters! The first tag will be less important then the second.
As example, if you have 3 Ui Elements with the following tags:
- element1: tag1, tag2, tag3
- element2: tag1, tag2
- element3: tag2, tag3
And you set the tags of your field to -tag1, tag2, -tag3
, then the only available Ui Element will be: element2
.
They all have the tag2 to include them, but the element1 and element3 have the tag3 which is excluding them after being both included.
Example of setting tags to an Ui Element using yaml
Deactivate an available element
Here is what really happens when deactivating an Ui Element:
- it's not displayed anymore in frontend
- it's still editable in backend for old contents but you can't add a new one
- if the element has an alias, the alias is treated the same way
Define the overload of a proposed UiElement in your configuration folder, let's say in config/packages/monsieurbiz_sylius_richeditor_plugin.yaml
as example.
Available elements
Row Element (Layout)
It contains another rich editor field, each element will be displayed one below the other (as rows…).
Column Element (Layout)
It contains another rich editor field, each element will be displayed side by side (as columns…).
By using this element in the Row
element, you will be able to build some layout like the screenshot below.
You can distinguish the Row
element and the Column
element by their dotted borders.
HTML Element
Markdown Element
You can use MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_SHOP
to enable code highlighting in the shop.
Also you can change the theme with MONSIEURBIZ_SYLIUS_RICH_EDITOR_ENABLED_HIGHLIGHT_JS_THEME
.
Text element
Quote element
Image element
Video element
Button element
Title element
Separator element
Youtube element
Image collection element
Example of a rich product description
Admin form with preview
Front display
Create your own elements
In this example, we will add a Google Maps element.
With the Maker Bundle, you can create a new UiElement very easily:
Then you will have to answer some questions, or you can add arguments to the command to avoid the questions.
Just add the translations!
Define your UiElement (for PHP < 8.1)
Tips: If you are using PHP 8.1 or newer, you can use the #[AsUiElement]
attribute to define your UiElement. You can skip this step.
Define your UiElement in your configuration folder, let's say in config/packages/monsieurbiz_sylius_richeditor_plugin.yaml
as example.
You can use your own Ui Element object if needed. Be sure to implement the
\MonsieurBiz\SyliusRichEditorPlugin\UiElement\UiElementInterface
interface.
A trait is there for you 🤗 as well. This is very useful when you need to do some custom work in your templates, it's like
having a helper around. The Ui Element is then available via the ui_element
variable in your templates.
Create the Form Type we use in admin to fill your UiElement
For PHP 8.1 and newer, you can use the #[AsUiElement]
attribute to define your UiElement. For example:
The title, description and templates values are generated automatically from the code. In this example :
- the title will be
app.ui_element.google_maps.title
, - the description will be
app.ui_element.google_maps.description
, - the admin template will be
/Admin/UiElement/google_maps.html.twig
, - and the front template will be
/Shop/UiElement/google_maps.html.twig
.
But you can override them if you want:
Add your translations of course
Here is an example of possible translation for the GMap element :
Create the templates to render it in front and in admin
You have to create a template for the front and also for the admin's preview.
Here is an example of a simple template for this our which can be used in front and admin:
The result !
The element is in the UI Elements list
You now have a form to edit it (your form!)
And we use your templates to render your UiElement
In admin :
In front :
File in fixtures management
In some cases you will want to add UI elements to your content fixtures which are Rich Editor fields. If you need files in your UI elements, you can use a dedicated fixture. It is used as follows.
The example below will copy files to public/media/image/foo/bar1.png
and public/media/foo/file.pdf
.
Now you can use files in your content fixtures:
Wireframes
You can add a wireframe to your UiElement. It will be displayed in the admin form to help the user to understand what the UiElement is about. The file can be either:
- An SVG with a
.twig
extension. Example:button.svg.twig
. - A classic twig template. Example
button.html.twig
. You can add the files in the folder :templates/MonsieurBizSyliusRichEditorPlugin/Wireframe/*.{svg/html}.twig
In the YAML declaration of a UI Element, you can add the wireframe key with the name of the file without the extension.
Wysiwyg Type
The WysiwygType
form type is a custom form type provided by the MonsieurBiz Sylius Rich Editor plugin. It extends the
Symfony's TextareaType
and provides a rich text editor interface in the admin form. It will work only in admin.
Basic Usage
To use the WysiwygType
in your form, you can add it to your form builder like this:
Options
The WysiwygType
form type accepts several options:
editor_type
: The type of the editor. Default isSunEditor::TYPE
. At this time, the only supported editor type isSunEditor::TYPE
.editor_height
: The height of the editor in pixels. Default is300
.editor_locale
: The locale of the editor. Default is the current admin locale or 'en' if it cannot be determined.editor_toolbar_type
: The type of the toolbar. It can be one of the following:EditorInterface::TOOLBAR_TYPE_MINIMAL
,EditorInterface::TOOLBAR_TYPE_BASIC
,EditorInterface::TOOLBAR_TYPE_FULL
,EditorInterface::TOOLBAR_TYPE_CUSTOM
. Default isEditorInterface::TOOLBAR_TYPE_BASIC
.editor_toolbar_buttons
: An array of buttons to be displayed in the toolbar wheneditor_toolbar_type
isEditorInterface::TOOLBAR_TYPE_CUSTOM
. Default isnull
.editor_custom_config
: An array of custom configuration options for the editor. Default isnull
.
Here is an example of how to use these options:
In this example, we have set a custom editor type, increased the height of the editor, set the locale to French, chosen a full toolbar, specified the buttons to be displayed in the toolbar, and provided some custom configuration options for the editor.
Contributing
You can open an issue or a Pull Request if you want! 😘
Thank you!
All versions of sylius-rich-editor-plugin with dependencies
sylius/sylius Version >=1.11 <1.14
twig/markdown-extra Version ^2.16|^3.12
twig/extra-bundle Version ^2.16|^3.12
league/commonmark Version ^2.5