简体   繁体   English

TYPO3自定义元素颜色选择器

[英]TYPO3 Custom Element colorpicker

I'm new to TYPO3 (first project) and I have some understanding issues of the creation of a custom element with a colorpicker. 我是TYPO3(第一个项目)的新手,我对使用色标创建自定义元素有一些了解。 In this project I already have created a few elements but I only use predetermined fields for the backend input. 在这个项目中,我已经创建了一些元素,但是我仅将预定字段用于后端输入。 For the element I need next I need the user to choose a color. 对于下一个元素,我需要用户选择一种颜色。 I haven't found a fitting existing element. 我还没有找到合适的现有元素。 My setup that doesn't work is in the TCA/Overrides/tt_content.php file and looks like this. 我无法使用的设置位于TCA/Overrides/tt_content.php文件中,如下所示。

$GLOBALS['TCA']['tt_content']['item_0']=array();            
$GLOBALS['TCA']['tt_content']['item_0']['label']='Color';
$GLOBALS['TCA']['tt_content']['item_0']['config']=array();
$GLOBALS['TCA']['tt_content']['item_0']['config']['type']='input';
$GLOBALS['TCA']['tt_content']['item_0']['config']['renderType']='colorpicker';
$GLOBALS['TCA']['tt_content']['item_0']['config']['size']=10;

$GLOBALS['TCA']['tt_content']['types']['wo_mitem'] = array(
    'showitem' => '--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.general;general,
        header;Title,
        subheader;Background,
        header_link;Target,
        item_0;Color,
        bodytext;Text;;richtext:rte_transform[flag=rte_enabled|mode=ts_css]
        ');

The item_0 was a try to create a colorpicker but it doesn't seem to work. item_0尝试创建颜色选择器,但似乎不起作用。 Do I need something different in a different file? 我在其他文件中需要其他内容吗? The first few lines I added to define my field. 我添加来定义字段的前几行。 Is there a better way to do this? 有一个更好的方法吗?

All other files in my custom extension work (since all other custom elements work fine). 自定义扩展名中的所有其他文件都可以工作(因为所有其他自定义元素都可以正常工作)。 The only difference is, as said, the need of a way to choose a color in the new one. 如上所述,唯一的区别是需要一种在新颜色中选择颜色的方法。

Just for a clearer look here the other files 只是为了更清晰地查看其他文件

setup.txt: setup.txt:

lib.contentElement {
  templateRootPaths {
    100 = EXT:wostyle/Resources/Private/Template
  }
}
tt_content {
    wo_mitem < lib.contentElement
    wo_mitem {
        templateName = MItem
    }
}

tt_content.php tt_content.php

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
   array(
      'WO_Item (ItemBox, Text only)',
      'wo_mitem',
      'content-image'
   ),
   'CType',
   'wostyle'
);

$GLOBALS['TCA']['tt_content']['item_0']=array();            
$GLOBALS['TCA']['tt_content']['item_0']['label']='Farbe';
$GLOBALS['TCA']['tt_content']['item_0']['config']=array();
$GLOBALS['TCA']['tt_content']['item_0']['config']['type']='input';
$GLOBALS['TCA']['tt_content']['item_0']['config']['renderType']='colorpicker';
$GLOBALS['TCA']['tt_content']['item_0']['config']['size']=10;

$GLOBALS['TCA']['tt_content']['types']['wo_mitem'] = array(
            'showitem' => '--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.general;general,
            header;Bezeichnung,
            subheader;Chemische Bezeichnung,
            header_link;Zielseite,
            item_0;Farbe,
            bodytext;Text;;richtext:rte_transform[flag=rte_enabled|mode=ts_css]
            ');

typo.ts 错别字

mod.wizards.newContentElement.wizardItems.wo_extra {
   header = WO Elemente
   after = common
  elements {
    wo_mitem {
         iconIdentifier = content-image
         title = WO_Item (ItemBox, Text only)
         description = Ein Produktfeld mit Text
         tt_content_defValues {
            CType = wo_mitem
         }
      }
   }
   show := addToList(wo_mitem)
}

MItem.html MItem.html

<div class="item-text">
    <f:link.typolink parameter="{data.header_link}">
        <div class="item-front">
            <f:if condition="{data.subheader}!=''">
            <f:then>
            <div class="item-bg">
                <f:format.html>{data.subheader}</f:format.html>
            </div>
            </f:then>
            </f:if>
            <div class="item-title">
                <f:format.html>{data.header}</f:format.html>
            </div>
        </div>
        <div class="item-back">
            <f:format.html>{data.bodytext}</f:format.html>
        </div>
    </f:link.typolink>
</div>
<f:debug>{data}</f:debug>

EDIT: I use typo3 8.7.8 编辑:我使用typo3 8.7.8

I did not check your whole code but I have a working color-picker on a field ... you're close but an error that pops up right away is that your item should be placed under ['columns'] ... 我没有检查您的整个代码,但是我在一个字段上有一个工作中的颜色选择器...您已经关闭,但是立即弹出的错误是您的项目应放在['columns'] ...

$GLOBALS['TCA']['tt_content']['columns']['item_0']=array();

next you are missing the refference to the wizard !! 接下来,您会丢失对向导的引用! (you should adopt the annotation with square brackets which shows much more the structure) (您应该采用带方括号的注释,该注释会显示更多结构)

this should be stored in Configuration/TCA/Overrides/tt_content.php : (when you override existing fields, otherwise you have a dedicated code for the element) 这应该存储在Configuration/TCA/Overrides/tt_content.php :( 当您覆盖现有字段时,否则,该元素具有专用代码)

<?php

/***************
 * Modify the tt_content TCA
 */
$tca = [
    'columns' => [
        'item_0' => [
            'label' => 'Color',
            'config' => [
                'type' => 'input',
                'size' => 10,
                'eval' => 'trim',
                'default' => '#ffffff',
                'wizards' => [
                    'colorChoice' => [
                        'type' => 'colorbox',
                        'title' => 'LLL:EXT:lang/locallang_wizards:colorpicker_title',
                        'module' => [
                            'name' => 'wizard_colorpicker'
                        ],
                        'dim' => '20x20',
                        'JSopenParams' => 'height=600,width=380,status=0,menubar=0,scrollbars=1',
                    ],
                ],
            ],
        ],
    ],
];
$GLOBALS['TCA']['tt_content'] = array_replace_recursive($GLOBALS['TCA']['tt_content'], $tca);

With the help of webMan and some internet searches I could adopt my code a little. 借助webMan和一些Internet搜索,我可以稍微采用我的代码。 I added the file "ext_tables.sql" with the content 我在文件“ ext_tables.sql”中添加了内容

CREATE TABLE tt_content (
    item_0 varchar(10) DEFAULT '' NOT NULL,
);

And changed the tt_content.php in TCA/Overrides to: 并将TCA / Overrides中的tt_content.php更改为:

$temporaryColumns = Array(
    "item_0" => Array(
        'label' => 'Color',
        'config' => Array(
            'type' => 'input',
            'renderType' => 'colorpicker',
            'size' => 10
        )
    )
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns('tt_content',$temporaryColumns);

$GLOBALS['TCA']['tt_content']['types']['wo_mitem'] = array(
            'showitem' => '--palette--;LLL:EXT:cms/locallang_ttc.xlf:palette.general;general,
            header;Bezeichnung,
            subheader;Chemische Bezeichnung,
            header_link;Zielseite,
            item_0;Farbe,
            bodytext;Text;;richtext:rte_transform[flag=rte_enabled|mode=ts_css]
            ');

There are still a view things missing in compare to webMans code but at least this is the first working version I have so i figured i show it since my question is answered:). 与webMans代码相比,仍然存在一些视图缺失的东西,但是至少这是我拥有的第一个工作版本,因此我认为自从我的问题得到回答以来,我都展示了它:)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM