Magento 2: Need to add custom module grid link in system config tab
-
18-03-2021 - |
Solution
If you want to show link in your system configuration, then please follow below steps :
You need to add field in your system.xml
file like this
<field id="link" translate="label" type="label" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Click here to see the logs</label>
<frontend_model>Vendor\Module\Block\Adminhtml\System\Config\Form\Field\Link</frontend_model>
</field>
Here we used frontend_model
and we will create Block for it here in custom module..
app/code/Vendor/Module/Block/Adminhtml/System/Config/Form/Field/Link.php
Content for this file..
<?php
namespace Vendor\Module\Block\Adminhtml\System\Config\Form\Field;
class Link extends \Magento\Config\Block\System\Config\Form\Field
{
public function __construct(
\Magento\Backend\Block\Template\Context $context,
array $data = []
) {
parent::__construct($context, $data);
}
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return sprintf(
'<a href ="%s">%s</a>',
rtrim($this->_urlBuilder->getUrl('custom/module/link'), '/'), //You need to change this link (Use your grid link like 'sales/order/index' will redirect you on order grid page.)
__('Marketo Logs')
);
}
}
Hope this will help you!
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange