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 /**
17 * {@inheritdoc}
18 */
19 public function up(Schema $schema, QueryBag $queries): void
20 {
21 if (!$schema->hasTable('acme_blog_post')) {
22 return;
23 }
24
25 $table = $schema->getTable('acme_blog_post');
26 if (!$table->hasColumn('content')) {
27 return;
28 }
29
30 $table->changeColumn(
31 'content',
32 [
33 'type' => WYSIWYGType::getType('wysiwyg'),
34 'notnull' => false,
35 'comment' => '(DC2Type:wysiwyg)',
36 ]
37 );
38 $table->addColumn(
39 'content_style',
40 'wysiwyg_style',
41 [
42 'notnull' => false,
43 OroOptions::KEY => [
44 ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
45 'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
46 ],
47 ]
48 );
49 $table->addColumn(
50 'content_properties',
51 'wysiwyg_properties',
52 [
53 'notnull' => false,
54 OroOptions::KEY => [
55 ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
56 'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
57 ],
58 ]
59 );
60 }
61}