繁体   English   中英

TYPO3自定义元素颜色选择器

[英]TYPO3 Custom Element colorpicker

我是TYPO3(第一个项目)的新手,我对使用色标创建自定义元素有一些了解。 在这个项目中,我已经创建了一些元素,但是我仅将预定字段用于后端输入。 对于下一个元素,我需要用户选择一种颜色。 我还没有找到合适的现有元素。 我无法使用的设置位于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]
        ');

item_0尝试创建颜色选择器,但似乎不起作用。 我在其他文件中需要其他内容吗? 我添加来定义字段的前几行。 有一个更好的方法吗?

自定义扩展名中的所有其他文件都可以工作(因为所有其他自定义元素都可以正常工作)。 如上所述,唯一的区别是需要一种在新颜色中选择颜色的方法。

只是为了更清晰地查看其他文件

setup.txt:

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

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]
            ');

错别字

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

<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>

编辑:我使用typo3 8.7.8

我没有检查您的整个代码,但是我在一个字段上有一个工作中的颜色选择器...您已经关闭,但是立即弹出的错误是您的项目应放在['columns'] ...

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

接下来,您会丢失对向导的引用! (您应该采用带方括号的注释,该注释会显示更多结构)

这应该存储在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);

借助webMan和一些Internet搜索,我可以稍微采用我的代码。 我在文件“ ext_tables.sql”中添加了内容

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

并将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]
            ');

与webMans代码相比,仍然存在一些视图缺失的东西,但是至少这是我拥有的第一个工作版本,因此我认为自从我的问题得到回答以来,我都展示了它:)。

暂无
暂无

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

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