Answers:
终于我得到了答案
我引用此模块并在我的自定义模块中实现
查找以下有用的代码:
遵循以下步骤
1)创建layout.xml
[vendor]/[module]/operation/view/adminhtml/layout/layout_edit.xml
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<uiComponent name="sample_form"/>
</referenceContainer>
<referenceContainer name="sample_form">
<block name="gallery" class="[vendor]\[module]\Block\Adminhtml\Grid\Helper\Form\Gallery">
<arguments>
<argument name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Images</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="opened" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">22</item>
<item name="canShow" xsi:type="boolean">true</item>
<item name="componentType" xsi:type="string">fieldset</item>
</argument>
</arguments>
<block class="[vendor]\[module]\Block\Adminhtml\Grid\Helper\Form\Gallery\Content" as="content" template="[vendor]_[[module]::helper/gallery.phtml">
<arguments>
<argument name="config" xsi:type="array">
<item name="parentComponent" xsi:type="string">sample_form.sample_form.block_gallery.block_gallery</item>
</argument>
</arguments>
</block>
</block>
</referenceContainer>
</body>
</page>
2)创建助手块
[vendor]/[module]/Block/Adminhtml/Grid/Helper/Form/Gallery.php
namespace [vendor]\[module]\Block\Adminhtml\Grid\Helper\Form;
use Magento\Framework\Registry;
use Magento\Catalog\Model\Product;
use Magento\Eav\Model\Entity\Attribute;
use Magento\Catalog\Api\Data\ProductInterface;
class Gallery extends \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery
{
/**
* @var here you set your ui form
*/
protected $formName = 'sample_form';
}
3)创建助手表格块
[vendor]\[module]\Block\Adminhtml\Grid\Helper\Form\Gallery\Content.php
namespace [vendor]\[module]\Block\Adminhtml\Grid\Helper\Form\Gallery;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Backend\Block\Media\Uploader;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\App\Filesystem\DirectoryList;
class Content extends \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content
{
protected function _prepareLayout()
{
$this->addChild('uploader', 'Magento\Backend\Block\Media\Uploader');
$a = $this->getUploader()->getConfig()->setUrl(
$this->_urlBuilder->addSessionParam()->getUrl('[vendor]/grid_gallery/upload')/* here set you upload Controller */
)->setFileField(
'image'
)->setFilters(
[
'images' => [
'label' => __('Images (.gif, .jpg, .png)'),
'files' => ['*.gif', '*.jpg', '*.jpeg', '*.png'],
],
]
);
}
public function getImageTypes()
{
return '[]';
}
public function getMediaAttributes()
{
return '[]';
}
}
注意 :-您应该在两个块上方正确扩展
4)创建模板
您应该复制gallery.phtml表单vendor/magento/module-product-video/view/adminhtml/templates/helper/gallery.phtml
并将其修改为符合您的要求,并破坏模块中的内容[vendor]/[module]/view/adminhtml/templates/helper/gallery.phtml
如果您需要任何帮助,请在评论中让我知道
protected $formName = 'your_ui_form
要在Magento 2中添加视频,您必须执行以下步骤:
Deexit Sanghani的答案可能已过时,因为我使用的是magento2.2.2 v,xml的位置对我而言不起作用,[vendor]/[module]/operation/view/adminhtml/layout/layout_edit.xml
但其他所有内容也都正确使用了。这是对我有用的东西,请看一下../vendor/magento/module-product-video/view/adminhtml/ui_component/product_form.xml
您所在的模块位置:../app/code/[vendor]/[module]/view/adminhtml/ui_component/your_ layout_edit.xml
在<form></form>
add中:
<htmlContent name="gallery" sortOrder="22">
<argument name="data" xsi:type="array">
<item name="wrapper" xsi:type="array">
<item name="label" xsi:type="string" translate="true">My Custom Images And Videos</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="opened" xsi:type="boolean">false</item>
</item>
</argument>
<settings>
<wrapper>
<canShow>true</canShow>
<componentType>fieldset</componentType>
</wrapper>
</settings>
<block name="gallery" class="[vendor]\[module]\Block\Adminhtml\[Entity]\Helper\Form\Gallery">
<!--<arguments>
<argument name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Images And Videos</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="opened" xsi:type="boolean">false</item>
<item name="sortOrder" xsi:type="string">22</item>
<item name="canShow" xsi:type="boolean">true</item>
<item name="componentType" xsi:type="string">fieldset</item>
</argument>
</arguments>-->
<block class="[vendor]\[module]\Block\Adminhtml\[Entity]\Helper\Form\Gallery\Content" as="content">
<arguments>
<argument name="config" xsi:type="array">
<item name="parentComponent" xsi:type="string">ui_component_form.ui_component_form.block_gallery.block_gallery</item>
</argument>
</arguments>
<block class="Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo" name="new-video" template="Magento_ProductVideo::product/edit/slideout/form.phtml"/>
</block>
</block>
</htmlContent>
我有管理上传图像添加自定义角色等。但不保存在数据库中尚未对行,注意:它需要很多的关注,使之适用于您的需求,覆盖您的需求例如gallery.pthml
,getImagesJson()
,getImageTypes()
,getMediaAttributes
方法等。 。然后需要密切匹配遵循相同的模式或类似于天然的Magento看表的数据库结构: catalog_product_entity_media_gallery_value
,catalog_product_entity_media_gallery
,catalog_product_entity_media_gallery_value
等...还没有对视频的工作呢!
希望对某人有所帮助!