我正在为magento 2.1.3 ce
开发扩展程序。我想在admin-panel的产品网格中添加指向每个产品的链接:
我想在此专栏中有一个链接,如何更改我的扩展名以获得链接而不是纯文本?
我的Magento扩展代码( app\code\MyCompany\ExampleAdminNewPage\view\adminhtml\ui_component\product_listing.xml
):
<?xml version="1.0"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns" class="Magento\Catalog\Ui\Component\Listing\Columns">
<column name="sku">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="add_field" xsi:type="boolean">true</item>
<item name="label" xsi:type="string" translate="true">Custom Field2</item>
<item name="sortOrder" xsi:type="number">75</item>
</item>
</argument>
</column>
</columns>
</listing>
在伪代码中我想要的是:
<column name="{http://mysite/}"+"sku">
答案 0 :(得分:0)
如果该URL是内部URL,请尝试以下操作:
第1步:像这样配置列:
<column name="custom_field2" class="MyCompany\ExampleAdminNewPage\Ui\Component\Listing\Column\HTMLLink">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<!-- other configurations -->
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
</item>
</argument>
</column>
步骤2:创建文件<Magento_ROOT>/app/code/MyCompany\ExampleAdminNewPage/Ui/Component/Listing/Column/HtmlLink.php
use Magento\Framework\Escaper;
use Magento\Ui\Component\Listing\Columns\Column;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
class HTMLLink extends Column{
protected $escaper;
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
Escaper $escaper,
array $components = [],
array $data = []
) {
$this->escaper = $escaper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
public function prepareDataSource(array $dataSource){
if (isset($dataSource['data']['items'])) {
$fieldName = $this->getData('name');
foreach ($dataSource['data']['items'] as & $item) {
$html = '<a href="some_internal_url" target="_blank">product</a>';
$item[$fieldName] = $this->escaper->escapeHtml($html, ['a']);
}
}
return $dataSource;
}
}