How to add new widgets in Magento 2

The following steps help you to add new widgets in Magento 2:

Step 1: Create a new category attribute with install schema file.

Step 2: Create an xml file.

 Step 1: Create a new category attribute with install schema file


namespace Magestore\CategoryAttribute\Setup;

use Magento\Framework\Setup\InstallDataInterface;

use Magento\Framework\Setup\ModuleContextInterface;

use Magento\Framework\Setup\ModuleDataSetupInterface;

use Magento\Eav\Setup\EavSetup;

use Magento\Eav\Setup\EavSetupFactory;

use Magento\Catalog\Model\Category;

use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;


* @codeCoverageIgnore


class InstallData implements InstallDataInterface



 * @var EavSetupFactory


 private $eavSetupFactory;



* @param EavSetupFactory $eavSetupFactory


 public function __construct(EavSetupFactory $eavSetupFactory)


$this->eavSetupFactory = $eavSetupFactory;


 public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)


/** @var EavSetup $eavSetup */

$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);





 'type' => 'varchar',

'label' => 'Custom attribute',

'input' => 'text',

 'required' => false,

 'sort_order' => 100,

 'global' => ScopedAttributeInterface::SCOPE_STORE,

'group' => 'General Information',






Step 2: Create an xml file

<?xml version="1.0" encoding="UTF-8"?>

<form xmlns:xsi=""


 <fieldset name="custom_content">

 <argument name="data" xsi:type="array">

 <item name="config" xsi:type="array">

 <item name="label" xsi:type="string" translate="true">Custom Content</item>

<item name="collapsible" xsi:type="boolean">true</item>

 <item name="sortOrder" xsi:type="number">100</item>



 <field name="custom_attribute">

 <argument name="data" xsi:type="array">

<item name="config" xsi:type="array">

<item name="sortOrder" xsi:type="number">10</item>

<item name="dataType" xsi:type="string">string</item>

 <item name="formElement" xsi:type="string">input</item>

<item name="label" xsi:type="string" translate="true">Custom Attribute</item>

 <item name="required" xsi:type="boolean">false</item>







The above mentioned steps which help to add new widgets in Magento 2

Last Update: April 9, 2018  

February 8, 2018   628   Nandini Ramachandran    Start With Magento 2    
Total 1 Votes:

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Leave a Reply

Your email address will not be published. Required fields are marked *