Wednesday, February 17, 2016

Magento2 adminhtml wysiwyg in Custom Module

Just made my first magento2 module to store a bunch of site specific data.  Was having a bear of a time figuring out how to enable the wysiwyg editor.  A lot of google'd results were completely irrelevant or wrong.  Some were even extremely complicated, but alas, its super super super easy.

In your /edit

->addField(
            'item_name',
            'text', array(

in your little array of data variables, just add 'wysiwyg' => true
Thats it! no adding calls to the framework, no constructors needed or other extended classes, just 1 variable.

to be clear, here is a fully flushed out field.

     $fieldset->addField(  
       'menu',  
       'editor',  
       ['name' => 'menu',   
       'label' => __('Menu HTML'),   
       'title' => __('Menu HTML'),   
       'required' => true,  
       'wysiwyg' => true]  
     );  

So much simpler then people lead you on to believe.  Figured it out by reading the source code instead of all the bloggers and tutorials.  Go figure -.-

No comments:

Post a Comment