Important

You are browsing the documentation for version 4.2 of OroCommerce, OroCRM and OroPlatform, which is no longer maintained. Read version 5.1 (the latest LTS version) of the Oro documentation to get up-to-date information.

See our Release Process documentation for more information on the currently supported and upcoming releases.

How to Add WYSIWYG Field

To add a WYSIWYG field to an entity, you should add 3 columns in a migration with the following types: wysiwyg, wysiwyg_style, and wysiwyg_properties.

 1<?php
 2
 3namespace ACME\Bundle\WysiwygBundle\Migrations\Schema\v1_1;
 4
 5use Doctrine\DBAL\Schema\Schema;
 6use Oro\Bundle\EntityConfigBundle\Entity\ConfigModel;
 7use Oro\Bundle\EntityExtendBundle\EntityConfig\ExtendScope;
 8use Oro\Bundle\EntityExtendBundle\Migration\ExtendOptionsManager;
 9use Oro\Bundle\EntityExtendBundle\Migration\OroOptions;
10use Oro\Bundle\MigrationBundle\Migration\Migration;
11use Oro\Bundle\MigrationBundle\Migration\QueryBag;
12
13class AddTeaserField implements Migration
14{
15    /**
16     * {@inheritdoc}
17     */
18    public function up(Schema $schema, QueryBag $queries): void
19    {
20        if (!$schema->hasTable('acme_blog_post')) {
21            return;
22        }
23
24        $table = $schema->getTable('acme_blog_post');
25        if ($table->hasColumn('teaser')) {
26            return;
27        }
28
29        $table->addColumn('teaser', 'wysiwyg', [
30            'notnull' => false,
31            'comment' => '(DC2Type:wysiwyg)',
32            OroOptions::KEY => [
33                'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
34                'entity' => ['label' => 'acme.wysiwyg.blogpost.teaser.label'],
35            ],
36        ]);
37        $table->addColumn(
38            'teaser_style',
39            'wysiwyg_style',
40            [
41                'notnull' => false,
42                OroOptions::KEY => [
43                    ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
44                    'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
45                ],
46            ]
47        );
48        $table->addColumn(
49            'teaser_properties',
50            'wysiwyg_properties',
51            [
52                'notnull' => false,
53                OroOptions::KEY => [
54                    ExtendOptionsManager::MODE_OPTION => ConfigModel::MODE_HIDDEN,
55                    'extend' => ['is_extend' => true, 'owner' => ExtendScope::OWNER_CUSTOM],
56                ],
57            ]
58        );
59    }
60}