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

  • Can you please update your question with screenshots ? – Kishan Savaliya Nov 5 '19 at 5:55
  • @kishan Updated my comment withs screenshots – Shomita Nov 5 '19 at 6:09
  • @kishan Did you check this? – Shomita Nov 5 '19 at 6:36
  • I've updated my answer. Please review. – Kishan Savaliya Nov 5 '19 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. – Rohan Hapani Nov 5 '19 at 7:22
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!

| improve this answer | |
  • 1
    Let me know if it will works for you. – Kishan Savaliya Nov 5 '19 at 6:45
  • 1
    Yes, This works for me. You save my day. Thanks a lot:) – Shomita Nov 5 '19 at 6:55
  • You're most welcome Buddy :) – Kishan Savaliya Nov 5 '19 at 6:55

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.