Magento 2 自定义字段未在页面生成器中保存其值

问题描述 投票:0回答:1

我按照以下链接仅在页面构建器图像元素中添加自定义字段。

如何在 Magento 2 pagebuilder 的 HTML 中使用自定义字段?

但这并没有保存价值。当我单击“保存”按钮并重新加载页面时,它会显示一个空字段。

如何保值?

提前致谢

我想在图像元素中添加自定义文本字段并将其值保存到数据库并将其应用到前端。

magento2
1个回答
0
投票

在这里,我将解决方案分享给那些可能面临同样问题的人。

第 1 步:创建自定义模块。

第2步:在下面创建文件image.xml 应用程序/代码/供应商/模块/adminhtml/pagebuilder/content_type

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_PageBuilder:etc/content_type.xsd">
    <type name="image">
        <appearances>
            <appearance name="full-width"
                        preview_template="Magento_PageBuilder/content-type/image/full-width/preview"
                        master_template="Magento_PageBuilder/content-type/image/full-width/master">
                <elements>
                    <element name="image_dimension">
                        <attribute name="image_width" source="width"/>
                        <attribute name="image_height" source="height"/>
                    </element>
                </elements>
            </appearance>
        </appearances>
    </type>
</config>

第3步:在app/code/vendor/module/view/adminhtml/ui_component下创建文件pagebuilder_image_form.xml

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="seo">
        <field name="image_width" sortOrder="30" formElement="input">
            <settings>
                <label translate="true">Image Width</label>
                <validation>
                    <rule name="validate-string" xsi:type="boolean">true</rule>
                </validation>
            </settings>
        </field>
        <field name="image_height" sortOrder="31" formElement="input">
            <settings>
                <label translate="true">Image Height</label>
                <validation>
                    <rule name="validate-string" xsi:type="boolean">true</rule>
                </validation>
            </settings>
        </field>        
    </fieldset>
</form>

第 5 步:运行以下命令

php bin/magento 设置:升级 php bin/magento 静态:内容:部署 -f php bin/magento c:f

注意:在image.xml文件中,“source”属性是我们需要指定元素的地方。为了设置图像的高度和宽度,我分别使用了source =“height”和source =“width”。

© www.soinside.com 2019 - 2024. All rights reserved.