在Typo3后端模块中使用链接向导 [英] Using the link wizard in a Typo3 backend module

查看:52
本文介绍了在Typo3后端模块中使用链接向导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为此拉头发.

我使用Extension Builder创建了一个T3-Extension-后端模块.现在,我想为用户提供链接向导,以便她/他可以从T3-Tree中选择一个内部链接.

I created a T3-Extension - backend module - using Extension Builder. Now I want to provide the user with the link-wizard, so she/he can select an internal link from the T3-Tree.

我为此创建了一个TCA条目:

I created a TCA-Entry for this:

'url' => [
        'label' => 'Link',
        'exclude' => 1,
        'config' => [
            'type'  => 'input',
            'size'  => '50',
            'max'   => '256',
            'eval'  => 'trim',
            'renderType' => 'inputLink',
            'fieldControl' => [
                'linkPopup' => [
                    'options' => [
                        'blinkLinkOptions' => 'mail,page,spec,url,folder',
                        'blindLinkFields' => 'class,params,target,title',
                        'allowedExtensions' => 'html,php'
                    ],
                ],
            ],
            'fieldWizard' => [
                'localizationStateSelector' => [
                    'disabled' => false,
                ]
            ]
        ],
    ],

在fluid-template(视图)中,我只是使用这个:

In the fluid-template (the view) I'm simply using this:

<f:form.textfield property="url" />

根据文档,TCA配置应在输入字段后添加一个按钮.

According to the docs, the TCA-config should add a button after the input field.

但事实并非如此.

我做错什么了吗?还是根本行不通?

Am I doing something wrong or is this simply not working?

我还尝试在模板(具有链接浏览器视图帮助器)中使用flux,但是当我使用< flux:...> 时,表单中没有任何内容.

I also tried using flux in my templates (which has a link-browser view helper), but when I use <flux:...> nothing is rendered in the form.

使用Typo3 8.7

Using Typo3 8.7

推荐答案

我终于找到了解决方案.

I finally found a solution for this.

这是在我的扩展程序的控制器中

This is in the controller of my extension

$options = [
        'renderType' => 'inputLink',
        'tableName' => 'myTable',
        'fieldName' => 'url',
        'databaseRow' => [
            'uid' => $myModel->getUid(),
            'pid' => 0
        ],
        'parameterArray' => [
            'fieldConf' => [
                'label' => 'URL',
                'config' => [
                    'eval' => 'trim',
                    'size' => 1024,
                ],
            ],
            'itemFormElValue' => $myModel->getUrl(),
            'itemFormElName' => 'data[myTable][editform][url]',
            'itemFormElID' => 'data[mytable][editform][url]',
            'field' => 'url',
            'fieldChangeFunc' => [
                'TBE_EDITOR_fieldChanged' => "TBE_EDITOR.fieldChanged('mytable','editform','url','data[mytable][editform][url]');"
                ],

        ]
    ];

        $nodeFactory = new NodeFactory();
        $linkField = new InputLinkElement($nodeFactory, $options);
        $urlField = $linkField->render();

        $this->view->assign('renderedUrlField', $urlField['html']);

其中"mytable"是控制器使用的表,"editform"是表单名称,而"url"是用于存储值的数据库字段.

Where «mytable» is the table the controller uses, «editform» is the form-name and «url» is the database-field that's been used to store the value.

由于某种原因,您需要将表格命名为"editform",因为sysext-JS引用了该表格.

For some reason, you need to name your form «editform», since a sysext-JS refers to that.

您需要将其添加到控制器中以使其正常工作:

You need to add this to your controller to make this working:

use TYPO3\CMS\Backend\Form\Element\InputLinkElement;
use TYPO3\CMS\Backend\Form\NodeFactory;

在流体模板中,您必须使用:

And in the fluid-template, you have to use:

<f:format.raw>{renderedUrlField}</f:format.raw>

因为它返回html代码.

because it returns html-code.

现在初始化FormEngine

Now initialize the FormEngine

将其添加到您的Default.html中的< f:be.container ...> :

Add this to your Default.html in the section <f:be.container...>:

includeJsFiles="{
        1:'/typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.tbe_editor.js',
3:'/typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.inline.js',
        4:'/typo3/sysext/backend/Resources/Public/JavaScript/backend.js'
    }"

            includeRequireJsModules="{
        0:'{f:uri.resource(path:\'JavaScript/ckeditor/ckeditor.js\')}',
        4:'TYPO3/CMS/Backend/FormEngine',
        5:'TYPO3/CMS/Backend/FormEngineValidation',
        7:'TYPO3/CMS/Backend/ContextMenu',
        8:'TYPO3/CMS/Backend/FormEngineReview',
        9:'{f:uri.resource(path:\'JavaScript/main.js\')}'
      }"

我在这里也包括了ckeditor.

I included ckeditor as well here.

现在,您需要初始化FormEngine.我是在main.js中完成的:

And now, you need to initialize the FormEngine. I did this in main.js:

TYPO3.settings.FormEngine = {"formName":"editform"};

define(['jquery', 'TYPO3/CMS/Backend/FormEngine'], function($){
    'use strict';

    $(function(){
        TYPO3.FormEngine.initialize();
    });
});

第一行很重要,否则,JS将引发错误.

The first line is important, otherwise, the JS will throw an error.

希望这对某人有帮助.

这篇关于在Typo3后端模块中使用链接向导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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