如何在TYPO3 10中以自定义extbase扩展的flexform创建文件上载字段? [英] How to create a file upload field in flexform of a custom extbase extension in TYPO3 10?

查看:80
本文介绍了如何在TYPO3 10中以自定义extbase扩展的flexform创建文件上载字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在TYPO3 10中以extbase扩展的flexform创建文件上载字段,因为TYPO3 10不支持internal_type"file",所以我尝试了下面给出的代码.

I tried to create a file upload field in flexform of an extbase extension in TYPO3 10. since the internal_type "file" is not supported in TYPO3 10, I tried the below given code.

<settings.bgImage>
    <TCEforms>
        <label>Background Image</label>
        <config>
            <type>inline</type>
            <maxitems>1</maxitems>
            <foreign_table>sys_file_reference</foreign_table>
            <!--<foreign_field>uid_foreign</foreign_field>-->
            <foreign_table_field>tablenames</foreign_table_field>
            <foreign_label>uid_local</foreign_label>
            <foreign_sortby>sorting_foreign</foreign_sortby>
            <foreign_selector>uid_local</foreign_selector>
            <foreign_selector_fieldTcaOverride type="array">
            <config>
                <appearance>
                    <elementBrowserType>file</elementBrowserType>
                    <elementBrowserAllowed>jpg,jpeg,png,svg</elementBrowserAllowed>
                </appearance>
            </config>
            </foreign_selector_fieldTcaOverride>
            <foreign_match_fields type="array">
                <fieldname>image</fieldname>
            </foreign_match_fields>
            <appearance type="array">
                <newRecordLinkAddTitle>1</newRecordLinkAddTitle>
                <createNewRelationLinkTitle>Add Image</createNewRelationLinkTitle>
                <headerThumbnail>
                    <field>uid_local</field>
                    <height>64</height>
                    <width>64</width>
                </headerThumbnail>
            </appearance>
        </config>
    </TCEforms>
  </settings.bgImage>

但这也无法正常工作.请帮助我解决此问题. 谢谢

But this is also not working correctly. please help me to fix this. Thank you

推荐答案

此处是当前正在运行的完整FlexForm,仅包含一个FAL-Image字段. 配置再次更改...:-(

Here is a currently working complete FlexForm with only a single FAL-Image field. The config has changed again... :-(

    <T3DataStructure>
        <sheets>
            <sDEF>
                <ROOT>
                    <TCEforms>
                        <sheetTitle>Example 1</sheetTitle>
                    </TCEforms>
                    <type>array</type>
                    <el>
                        <!-- example of a working fal image -->
                        <images>
                            <label>FAL-Images</label>
                            <config>
                                <type>inline</type>
                                <foreign_table>sys_file_reference</foreign_table>
                                <foreign_field>uid_foreign</foreign_field>
                                <foreign_sortby>sorting_foreign</foreign_sortby>
                                <foreign_table_field>tablenames</foreign_table_field>
                                <foreign_match_fields>
                                    <!-- this will be stored in sys_file_reference.fieldname -->
                                    <fieldname>image</fieldname>
                                </foreign_match_fields>
                                <foreign_label>uid_local</foreign_label>
                                <foreign_selector>uid_local</foreign_selector>
                                <overrideChildTca>
                                    <columns>
                                        <uid_local>
                                            <config>
                                                <appearance>
                                                    <elementBrowserType>file</elementBrowserType>
                                                    <elementBrowserAllowed></elementBrowserAllowed>
                                                </appearance>
                                            </config>
                                        </uid_local>
                                    </columns>
                                </overrideChildTca>
                                <filter>
                                    <userFunc>TYPO3\CMS\Core\Resource\Filter\FileExtensionFilter->filterInlineChildren</userFunc>
                                    <parameters>
                                        <allowedFileExtensions></allowedFileExtensions>
                                        <disallowedFileExtensions></disallowedFileExtensions>
                                    </parameters>
                                </filter>
                                <appearance>
                                    <useSortable>1</useSortable>
                                    <headerThumbnail>
                                        <field>uid_local</field>
                                        <width>45</width>
                                        <height>45c</height>
                                    </headerThumbnail>
                                    <enabledControls>
                                        <info>1</info>
                                        <new>0</new>
                                        <dragdrop>1</dragdrop>
                                        <sort>0</sort>
                                        <hide>1</hide>
                                        <delete>1</delete>
                                    </enabledControls>
                                </appearance>
                            </config>
                        </images>
                        <!-- end -->
                    </el>
                </ROOT>
            </sDEF>
        </sheets>
    </T3DataStructure>

更新:我将在这里显示一个ViewHelper以及如何使用它...

Update: I'll show here a ViewHelper and how to use it...

{namespace t=Your\Extension\ViewHelpers}

<f:for each="{t:FAL(uid=entry.uid, field='image', table='tt_content')}" as="preview">
    <div class="preview">
        <f:image src="{f:uri.image(image=preview)}" title="{preview.title}" />
        <figcaption>{preview.title} {preview.description}</figcaption>
    </div>
</f:for>

ViewHelper示例

<?php
namespace Your\Extension\ViewHelpers;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FALViewHelper extends AbstractViewHelper
{
    use CompileWithRenderStatic;

    public function initializeArguments()
    {
        $this->registerArgument('table', 'string', '', false);
        $this->registerArgument('field', 'string', '', true);
        $this->registerArgument('uid', 'integer', '', true);
    }
    public static function renderStatic( array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
    {
        $resFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
        $table = $arguments['table'] != NULL ? $arguments['table'] : 'tt_content';
        $field = $arguments['field'];
        $uid = intval($arguments['uid']);

        $fileRepository = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\FileRepository::class);
        $fileObjects = $fileRepository->findByRelation($table, $field, $uid);

        return $fileObjects;
    }
}

说明

通过表sys_file_reference解析图像.

Explanation

The images are resolved thru the table sys_file_reference.

当您查看它时,会发现这些字段将填充您的扩展数据: -表名, -字段名和 -uid_foreign

When you take a look at it, you will find, that these fields will be filled with your extensions data: - tablenames, - fieldname and - uid_foreign

flexform字段可能将tt_content用作tablenames,将image用作fieldname,并将扩展名tt_content的uid记录为uid_foreign.

A flexform field will probably have tt_content as tablenames, image as fieldname and the uid of your extensions tt_content record as uid_foreign.

flexform定义了<fieldname>image</fieldname> ...这将成为fieldname.

The flexform defines the <fieldname>image</fieldname> ... this will become the fieldname.

模板必须告诉ViewHelper查找内容:{t:FAL(uid=entry.uid, field='image', table='tt_content')}

The template must tell the ViewHelper what to look for: {t:FAL(uid=entry.uid, field='image', table='tt_content')}

  • entry.uid必须与内容元素的uid匹配.
  • field ='image'必须与FlexForm字段名匹配.
  • 该表必须与存储数据的表匹配.(这里:tt_content)

如果在扩展名中使用它,则需要将表名更改为您的tx_yourextension_whatever. 您可能还会更改字段名称...

If you are using it in an extension you will need to change the tablename to your tx_yourextension_whatever. You will probably change the fieldname as well...

这段代码似乎仍然会产生一些过时的警告...我还没有弄清楚如何克服这些问题:-/

This code still seems to produce some deprecation warnings... I havn't yet figured out, how to overcome these :-/

这篇关于如何在TYPO3 10中以自定义extbase扩展的flexform创建文件上载字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆