Magento 2: Showing iFrame in Admin Configuration Panel

configurationiframemagento2magento2.2system-config

I want the users who download and install my extension from the marketplace to go through a registration/login flow. Since the normal system.xml file supports only static pages and doing the entire thing using FE models is too complicated, I'm wondering if I can instead show everything in an iframe?

Showing everything in an iframe gives me lot of advantages like –

  • Flexibility over design. Magento buttons/elements are ugly.
  • Being able to use the same iframe my other eCommerce offerings
  • Much much less engineering time since our team is much more comfortable with JavaScript/CSS than PHP/XML etc

So my question is how to implement the iframe and are there any disadvantages that I'm missing?

I see its possible for Magento 1

Best Answer

You need to create custom type in form

$fieldset->addType('map', '\Vendor\Module\Block\Adminhtml\Youblock\Renderer\Map');

$fieldset->addField(
    'file',
    'map',
    [
        'name'  => 'map',
        'label' => __('Map'),
        'title' => __('Map'),

    ]
);

app/code/Vendor/Module/Block/Adminhtml/Yourblock/Renderer/Map.php

<?php

namespace Vendor\Module\Block\Adminhtml\Yourblock\Renderer;

use Magento\Framework\DataObject;

class Map extends \Magento\Framework\Data\Form\Element\AbstractElement
{
    public function getElementHtml()
    {
        $iframe = "<iframe>Your iframe Here</iframe>";
        return $iframe;
    }

}