EXT:Form - 从内容对象数据中获取布局字段



我正在尝试获取ext:form内容元素中内容对象数据的布局字段,以便在选择了特定布局的情况下添加css类。但是,内容对象数据被添加到流体模板(typo3/sysext/form/Classes/Controller/FormFrontendController.php:73(中,也不会为该元素渲染fluid_styled_content的帧容器。我的布局字段配置如下:

TCEFORM.tt_content {
    layout {
        types.form_formframework {
            addItems {
                200 = Blue Form
            }
            removeItems = 1,2,3
        }
    }
}

我还尝试向表单配置本身添加新的布局字段:

TYPO3:
  CMS:
    Form:
      ########### FORMEDITOR CONFIGURATION ###########
      prototypes:
        standard:
          ########### DEFAULT FORM ELEMENT DEFINITIONS ###########
          formElementsDefinition:
            Form:
              formEditor:
                editors:
                  9000:
                    identifier: 'layout'
                    group: select
                    templateName: 'Inspector-SingleSelectEditor'
                    label: 'Layout'
                    propertyPath: 'properties.layout'
                    selectOptions:
                      0:
                        value:
                        label: Normal
                      1:
                        value: form--blue
                        label: Blau

这在后端效果很好,但在前端会导致The options "properties" were not allowed错误,因为表单元素的属性是用 typo3/sysext/form/Classes/Domain/Model/FormDefinition.php:382 硬编码的。

任何想法如何在此处添加布局选择?最好是在内容元素上,因为这将允许我使用相同的表单配置和不同的布局,而不是制作仅在布局中区分的重复表单配置。

内容对象数据在fluid_styled_content的泛型模板中可用。在这里,您可以检查 Ctype 是否为"form_formframework",并用您的 css 类包装表单。

<f:if condition="{content}">
<f:then>
    {content -> f:format.raw()}
</f:then>
<f:else>
    <f:if condition="{data.CType} == 'form_formframework'">
        <f:then>
            <div class="{data.layout}">
                <f:cObject typoscriptObjectPath="tt_content.{data.CType}.20" data="{data}" table="tt_content"/>
            </div>
        </f:then>
        <f:else>
            <f:cObject typoscriptObjectPath="tt_content.{data.CType}.20" data="{data}" table="tt_content"/>
        </f:else>
    </f:if>
</f:else>
</f:if>

我们可以将流体模板布局添加到默认fluid_style_content/资源/私有/布局/默认.html (我们可以覆盖网站模板中的流体模板( - 无需考虑覆盖表单的完成器和 Flexform 值:

<f:if condition="{data.CType} == 'form_formframework'">
    <f:then>
        <section id="c{data.uid}" class="form-section {f:if(condition:'{data.layout}',then:'blue')}">
            <f:if condition="{data._LOCALIZED_UID}">
                <a id="c{data._LOCALIZED_UID}"></a>
            </f:if>
            <f:render section="Before" optional="true">
                <f:render partial="DropIn/Before/All" arguments="{_all}" />
            </f:render>
            <f:render section="Header" optional="true">
                <f:render partial="Header/All" arguments="{_all}" />
            </f:render>
            <f:render section="Main" optional="true" />
            <f:render section="Footer" optional="true">
                <f:render partial="Footer/All" arguments="{_all}" />
            </f:render>
            <f:render section="After" optional="true">
                <f:render partial="DropIn/After/All" arguments="{_all}" />
            </f:render>
        </section>
    </f:then>
    <f:else>
        <div id="c{data.uid}" class="frame frame-{data.frame_class} frame-type-{data.CType} frame-layout-{data.layout}{f:if(condition: data.space_before_class, then: ' frame-space-before-{data.space_before_class}')}{f:if(condition: data.space_after_class, then: ' frame-space-after-{data.space_after_class}')}">
            <f:if condition="{data._LOCALIZED_UID}">
                <a id="c{data._LOCALIZED_UID}"></a>
            </f:if>
            <f:render section="Before" optional="true">
                <f:render partial="DropIn/Before/All" arguments="{_all}" />
            </f:render>
            <f:render section="Header" optional="true">
                <f:render partial="Header/All" arguments="{_all}" />
            </f:render>
            <f:render section="Main" optional="true" />
            <f:render section="Footer" optional="true">
                <f:render partial="Footer/All" arguments="{_all}" />
            </f:render>
            <f:render section="After" optional="true">
                <f:render partial="DropIn/After/All" arguments="{_all}" />
            </f:render>
        </div>
    </f:else>
</f:if>

希望对大家有所帮助!

最新更新