murph-doc/docs/utils/editors/tinymce.md

174 lines
3.3 KiB
Markdown
Raw Normal View History

2022-04-19 11:38:55 +02:00
# TinyMCE
TinyMCE gives you total control over your rich text editing. It's fully integrated in Murph as form types.
2022-04-19 11:47:32 +02:00
![](/_static/img/editors/tinymce.png)
2022-04-19 11:38:55 +02:00
## Classic form
2023-02-09 21:50:06 +01:00
```php-inline title="src/Form/ExampleType.php"
2022-04-19 11:38:55 +02:00
namespace App\Form\ExampleType;
use App\Core\Form\Type\TinymceTextareaType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class ExampleType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'myField',
TinymceTextareaType::class
);
// ...
}
// ...
}
```
## Page form
2023-02-09 21:50:06 +01:00
```php-inline title="src/Entity/Page/YourPage.php"
2022-04-19 11:38:55 +02:00
namespace App\Entity\Page;
use App\Core\Entity\Site\Page\Block;
use App\Core\Form\Site\Page\TinymceTextareaBlockType;
2023-02-09 21:50:06 +01:00
#[ORM\Entity]
2022-04-19 11:38:55 +02:00
class YourPage extends Page
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'myBlock',
TinymceTextareaBlockType::class,
[
'label' => 'My block',
'row_attr' => [
],
'options' => [
// options given to the sub form
],
]
);
// ...
}
public function setMyBlock(Block $block)
{
return $this->setBlock($block);
}
public function getMyBlock(): Block
{
return $this->getBlock('myBlock');
}
// ...
}
```
## Options
There are 2 predefined modes:
* Default: `default`
* Light: `light`
To specify a mode, you must define the attribute `data-tinymce`:
2023-02-09 21:50:06 +01:00
```php-inline title="src/Form/ExampleType.php"
2022-04-19 11:38:55 +02:00
$builder->add(
'myField',
TinymceTextareaType::class,
[
// ...
'attr' => [
'data-tinymce' => 'light',
],
]
);
2023-02-09 21:50:06 +01:00
```
2022-04-19 11:38:55 +02:00
2023-02-09 21:50:06 +01:00
```php-inline title="src/Entity/Page/YourPage.php"
2022-04-19 11:38:55 +02:00
$builder->add(
'myBlock',
TinymceTextareaBlockType::class,
[
// ...
'options' => [
'attr' => [
'data-tinymce' => 'light',
],
],
]
);
```
To custom the editor, see the example below:
2023-02-09 21:50:06 +01:00
```javascript title="assets/js/admin.js"
2022-04-19 11:38:55 +02:00
import '../../vendor/murph/murph-core/src/core/Resources/assets/js/admin.js'
window.tinymce.language = 'fr_FR'
2024-03-31 17:02:51 +02:00
window.tinymceModes = {
myCustomMode: {
plugins: '...',
menubar: '...',
toolbar: '...'
quickbars_selection_toolbar: '...'
contextmenu: '...'
templates: [
{
title: 'Container',
description: 'Add a bootstrap container',
content: '<div class="container"><div class="selcontent"></div></div>'
}
// ...
],
content_style: '...'
}
2022-04-19 11:38:55 +02:00
}
2023-02-09 21:50:06 +01:00
```
2022-04-19 11:38:55 +02:00
2023-02-09 21:50:06 +01:00
```php-inline title="src/Form/ExampleType.php"
2022-04-19 11:38:55 +02:00
$builder->add(
'myField',
TinymceTextareaType::class,
[
// ...
'attr' => [
'data-tinymce' => 'myCustomMode',
],
]
);
2023-02-09 21:50:06 +01:00
```
2022-04-19 11:38:55 +02:00
2023-02-09 21:50:06 +01:00
```php-inline title="src/Entity/Page/YourPage.php"
2022-04-19 11:38:55 +02:00
$builder->add(
'myBlock',
TinymceTextareaBlockType::class,
[
// ...
'options' => [
'attr' => [
'data-tinymce' => 'myCustomMode',
],
],
]
);
```
## Rendering
2022-04-19 11:42:07 +02:00
TinyMCE generates HTML. To render, simply use `{{ value|raw }}`.