0

in system.xml:

<field id="custom_field" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
      <label>Custom Field</label>
      <source_model>Vendor\Module\Block\Adminhtml\System\Config\Custom</source_model>
</field>

Custom.php:

 namespace Vendor\Module\Block\Adminhtml\System\Config;
 use Magento\Framework\App\Config\ScopeConfigInterface;

class Custom extends \Magento\Config\Block\System\Config\Form\Field
{
protected $_template = 'Vendor_Module::system/config/custom.phtml';

const TEMPLATE = 'Vendor_Module::system/config/custom.phtml';

protected $_moduleManager;

/**
 *
 * @param \Magento\Backend\Block\Template\Context $context
 * @param ScopeConfigInterface $scopeConfig
 * @param \Magento\Framework\Module\Manager $moduleManager
 * @param \Magento\Framework\ObjectManagerInterface $objectmanager
 * @param array $data
 */
public function __construct(
    \Magento\Backend\Block\Template\Context $context,
    \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
    \Magento\Framework\Module\Manager $moduleManager,
    array $data = []
)
{
    $this->_scopeConfig     = $scopeConfig;
    $this->_moduleManager   = $moduleManager;
    parent::__construct($context, $data);
}

/**
 *
 * @return $this
 */
protected function _prepareLayout()
{
    parent::_prepareLayout();
    if (!$this->getTemplate()) {
        $this->setTemplate(static::TEMPLATE);
    }
    return $this;
}
/**
 * Retrieve element HTML markup.
 *
 * @param \Magento\Framework\Data\Form\Element\AbstractElement $element
 *
 * @return string
 */
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
    $this->setNamePrefix($element->getName())
        ->setHtmlId($element->getHtmlId());

    return $this->_toHtml();
}

}

custom.phtml: As an example but more then that basically any html element

<div class="test">
    <p>
        Click <a href="#">here</a>
    </p>
</div>
<select name="custom" class="select admin__control-select"
        data-ui-id="select-groups-third-fields-custom-value">
    <option value="no">No</option>
    <option value="yes">Yes</option>
</select>
<input type="checkbox" name="test" />

<p>END</p>
0

I've manage to add by using frontend_model:

<field id="my_field" translate="label comment" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
       <frontend_model>Vendor\Module\Block\System\Config\Custom</frontend_model>
       <label>Custom</label>
 </field>

Using this example:How to create a button in Magento 2 configuration section?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.