Magento – Magento 2 wysiwyg editor filter image

fieldsetsimagemagento2wysiwyg

I have custom module field code is bellow for wysiwyg field:-

 $wysiwygConfig = $this->_wysiwygConfig->getConfig(['tab_id' => $this->getTabId()]);
    $fieldset->addField(
                'news_content',
                'editor',
                [
                    'name' => 'news_content',
                    'label' => __('Long Description'),
                    'title' => __('Long Description'),
                    'style' => 'height:11em',
                    'required' => true,
                    'disabled' => $isElementDisabled,
                    'config' => $wysiwygConfig
                ]
            );

when i upload image in this field with content it only shows content and image is not come with proper tag as bellow:-

<p><img src="{{media url="wysiwyg/24.png"}}" alt="" /></p>
<p>test</p>

so there is a question that content filter we used in 1.9.X.X is not in magento 2.0.2.

how can i get image and description from wysiwyg editor with default filter to display image with content.

Best Answer

Use below code:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$objectManager->get('\Magento\Cms\Model\Template\FilterProvider')->getBlockFilter()->filter($item->getContent());

In above code $item->getContent() is your editor content

Related Topic