How to Change Textarea Field to WYSIWYG Field
To turn an existing text field of some entity into a WYSIWYG field:
Create a migration that changes the type of the existing column to
wysiwyg
and adds 2 new columns to store additional data associated with the WYSIWYG fields using the following types:wysiwyg_style
andwysiwyg_properties
.
1<?php
2
3namespace Acme\Bundle\WysiwygBundle\Migrations\Schema\v1_1;
4
5use Doctrine\DBAL\Schema\Schema;
6use Oro\Bundle\CMSBundle\DBAL\Types\WYSIWYGType;
7use Oro\Bundle\EntityConfigBundle\Entity\ConfigModel;
8use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
9use Oro\Bundle\EntityExtendBundle\Migration\ExtendOptionsManager;
10use Oro\Bundle\EntityExtendBundle\Migration\OroOptions;
11use Oro\Bundle\MigrationBundle\Migration\Migration;
12use Oro\Bundle\MigrationBundle\Migration\QueryBag;
13
14class UpdateContentField implements Migration
15{
16 #[\Override]
17 public function up(Schema $schema, QueryBag $queries): void
18 {
19 if (!$schema->hasTable('acme_blog_post')) {
20 return;
21 }
22
23 $table = $schema->getTable('acme_blog_post');
24 if (!$table->hasColumn('content')) {
25 return;
26 }
27
28 $table->changeColumn(
29 'content',
30 [
31 'type' => WYSIWYGType::getType('wysiwyg'),
32 'notnull' => false,
33 'comment' => '(DC2Type:wysiwyg)',
34 ]
35 );
36 $table->addColumn(
37 'content_style',
38 'wysiwyg_style',
39 [
40 'notnull' => false,
41 OroOptions::KEY => [
42 ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
43 'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
44 ],
45 ]
46 );
47 $table->addColumn(
48 'content_properties',
49 'wysiwyg_properties',
50 [
51 'notnull' => false,
52 OroOptions::KEY => [
53 ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
54 'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
55 ],
56 ]
57 );
58 }
59}