Magento 2 - Showing iframe in admin configuration panel
-
08-10-2020 - |
質問
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
解決
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;
}
}
他のヒント
As with frontend, you can implement a custom backend theme. As part of your custom theme, you can define and include a .phtml template which can include arbitrary HTML, CSS, Javascript, and PHP -- i.e. you can include an iframe via a template.
If you are not yet familiar with adding a template to your theme, I would get started with the DevDocs Frontend Developer Guide: Templates overview.