0

I have created a custom module grid in admin and need to add grid link to system config custom tab. I am struggling with this.

Custom module

enter image description here

System config field

enter image description here

How I can achieve this?

Thanks

5
  • Can you please update your question with screenshots ? Commented Nov 5, 2019 at 5:55
  • @kishan Updated my comment withs screenshots
    – Shomita
    Commented Nov 5, 2019 at 6:09
  • @kishan Did you check this?
    – Shomita
    Commented Nov 5, 2019 at 6:36
  • I've updated my answer. Please review. Commented Nov 5, 2019 at 6:36
  • It seems like your screenshot explain that you want to set link in label and answer related to display in link field. Commented Nov 5, 2019 at 7:22

1 Answer 1

1

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!

3
  • 1
    Let me know if it will works for you. Commented Nov 5, 2019 at 6:45
  • 1
    Yes, This works for me. You save my day. Thanks a lot:)
    – Shomita
    Commented Nov 5, 2019 at 6:55
  • You're most welcome Buddy :) Commented Nov 5, 2019 at 6:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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