How to add Radio button in Admin System Configuration of Magento 2

Magento 2 How to add Radio button in Admin System Configuration

In Magento, System Configurations have always stood apart from an extension that controls & contains tons of options. It’s like the heart of the extension that allows the store owner to handle all features & functionality seamlessly. Till today, we have created 100+ extensions and we are always focused to create admin configurations simple but effective the way love store owners willing to have. Because at the end of the day, it made for a store owner to reduce their efforts to maintain the store and deliver great user experience towards their store customer.

In Magento 2, it allows the developer to add tons of elements to admin interface like text files, radio buttons, dropdowns, and multiple selects, simple fields, images and more. We used to play with these system controls to fulfill each requirement we get. Even, we have published tons of article on adding various elements to system configuration and here is another for adding Radio button in the Admin System Configuration.

To add a radio button control to system configuration, you simply need to add an element by modifying ‘System.xml‘ by adding below code.
app\code\Vendor\Extension\etc\Adminhtml\system.xml

<pre class="lang:default decode:true">
              <label>Horizontal Alignment</label>
              Vendor\Extension\Model\Config\Source\Radiobtn

</pre>

Now create another file and named it ‘Radiobtn.php‘ and paste your own logic.
app\code\Vendor\Extension\Model\Config\Source\Radiobtn.php

<strong>app\code\Vendor\Extension\Model\Config\Source\Radiobtn.php</strong>
<pre class="lang:default decode:true"><!--?php namespace Vendor\Extension\Model\Config\Source; class Radiobtn implements \Magento\Framework\Option\ArrayInterface { public function toOptionArray() { return [['value' =&gt; 'left', 'label' =&gt; __('Left')], ['value' =&gt; 'right', 'label' =&gt; __('Right')],];
	}
}
</pre>

Also, you can play &amp; manipulate with these codes according to your need of adding one or more radio button choices inside the Magento System Configuration.
Lastly, smash that stars if you love reading our blogs and comment down below if you are facing an issue while using this code.
Happy Coding!

Previous Article

How to fix an error while uploading a logo from admin in Latest Magento 2.2.4

Next Article

How to Get Instagram Client ID and Client Secret for Magento Instagram Extension

Write a Comment

Leave a Comment

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

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨