【发布时间】:2021-03-06 09:24:39
【问题描述】:
我是 Typo3 的新手。我想在此内容元素中添加一个带有特定选择字段的自定义内容元素。 对于自定义内容元素,我修改了 pageTSConfig 与
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig 并添加了我的元素。这是有效的。为了存储我的内容值,我添加了“ext_tables.sql”文件
#
# Table structure for table 'tt_content'
#
CREATE TABLE tt_content (
tx_spk_shopware_category varchar(20) NULL
);
最后我覆盖了 tt_content 的 TCA 配置,这不起作用。我在配置中看到具有我的自定义类型的新内容元素和我的项目,但我无法修改/添加 itemsProcFunc 中引用的类中的任何项目。
tt_content.php:
<?php declare(strict_types=1);
defined('TYPO3_MODE') || die();
// static TypoScript
(static function () {
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPlugin(
array(
'LLL:EXT:spk_shopware/Resources/Private/Language/Tca.xlf:spk_shopware_category.wizard.title',
'spk_shopware_category',
'EXT:spk_shopware/Resources/Public/Icons/ContentElements/spk_shopware_category.gif'
),
'CType',
'spk_shopware'
);
$temporaryColumn = array(
'tx_spk_shopware_category' => array (
'exclude' => 1,
'label' => 'LLL:EXT:spk_shopware/Resources/Private/Language/Tca.xlf:spk_shopware_category.title',
'config' => array (
'type' => 'select',
'itemsProcFunc' => SPK\Shopware\Hook\ShopwareCategorySelect::class . '->listAvailableShopwareCategories',
'items' => array(
array('test 1', '8'),
array('test 2', '10'),
),
'maxitems' => 1,
'minitems' => 1,
'required' => true,
)
)
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTCAcolumns(
'tt_content',
$temporaryColumn
);
})();
// Configure the default backend fields for the content element
$GLOBALS['TCA']['tt_content']['types']['spk_shopware_category'] = array(
'showitem' => '
--palette--;LLL:EXT:frontend/Resources/Private/Language/locallang_ttc.xml:palette.general;general,
tx_spk_shopware_category
');
CategorySelect.php
<?php
namespace SPK\Shopware\Hook;
class ShopwareCategorySelect
{
public function listAvailableShopwareCategories(&$config)
{
$config['items'][] = ["Tim", 0];
$config['items'][] = ["Tom", 1];
$config['items'][] = ["Jerry", 2];
array_push($config['items'], ["as", 1]);
return $config;
}
}
我看到了自定义元素和新的选择字段,但只有配置中的测试元素。我不知道我错过了什么。
【问题讨论】:
-
你确定,TYPO3“知道”你的班级吗?你有某种自动加载信息(composer.json 或 ext_emconf.php 中的自动加载部分)吗?
-
@JulianHofmann 我在 ext_emconf.php 中添加了以下部分: 'autoload' => [ 'psr-4' => ['SPK\\Shopware\\' => 'Classes/'] ]
-
嗯,您的 sn-ps 描述类 ShopwareCategorySelect 在文件 CategorySelect.php 中 - 不是,自动加载如何工作。类名和文件名应该相同。
-
@JulianHofmann 抱歉。这是我的错。文件名为 ShopwareCategorySelect.php,我的 Classname 也是 ShopwareCategorySelect。
-
@JulianHofmann 这是自动加载部分。我在一个没有作曲家文件的克隆网站上工作。在我添加作曲家文件并调整自动加载部分后它工作。你想写一个答案。我可以接受它作为解决方案。 Danke nochmal dafür.