gpt4 book ai didi

php - TYPO3:创建新元素时重命名所有实体

转载 作者:行者123 更新时间:2023-12-02 19:32:28 27 4
gpt4 key购买 nike

我创建了一个在 TYPO3 6.2.30 上运行的扩展,它显示了一些具有相关 Material 、颜色等的产品。

Material 、颜色和产品是通过后端导入 csv 生成的,并由 PersistenceManager 保存。

但是如果客户想在列表模块的后端创建颜色,我会有一个奇怪的行为:

创建新颜色后,所有现有颜色和新颜色的名称都是(我认为)随机生成的数字。

型号:

class Color extends \TYPO3\CMS\Extbase\DomainObject\AbstractEntity {

/**
* name
*
* @var string
* @validate NotEmpty
*/
protected $name = '';

/**
* code
*
* @var integer
*/
protected $code = 0;


/**
* Returns the name
*
* @return string $name
*/
public function getName() {
return $this->name;
}

/**
* Sets the name
*
* @param string $name
* @return void
*/
public function setName($name) {
$this->name = $name;
}

/**
* Returns the code
*
* @return integer $code
*/
public function getCode() {
return $this->code;
}

/**
* Sets the code
*
* @param integer $code
* @return void
*/
public function setCode($code) {
$this->code = $code;
}
}

TCA:

$GLOBALS['TCA']['artikel_domain_model_color'] = array(
'ctrl' => $GLOBALS['TCA']['artikel_domain_model_color']['ctrl'],
'interface' => array(
'showRecordFieldList' => 'sys_language_uid, l10n_parent, l10n_diffsource, hidden, name, code',
),
'types' => array(
'1' => array('showitem' => 'sys_language_uid;;;;1-1-1, l10n_parent, l10n_diffsource, hidden;;1, name, code, --div--;LLL:EXT:cms/locallang_ttc.xlf:tabs.access, starttime, endtime'),
),
'palettes' => array(
'1' => array('showitem' => ''),
),
'columns' => array(
'sys_language_uid' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.language',
'config' => array(
'type' => 'select',
'foreign_table' => 'sys_language',
'foreign_table_where' => 'ORDER BY sys_language.title',
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
),
),
),
'l10n_parent' => array(
'displayCond' => 'FIELD:sys_language_uid:>:0',
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.l18n_parent',
'config' => array(
'type' => 'select',
'items' => array(
array('', 0),
),
'foreign_table' => 'artikel_domain_model_color',
'foreign_table_where' => 'AND artikel_domain_model_color.pid=###CURRENT_PID### AND artikel_domain_model_color.sys_language_uid IN (-1,0)',
),
),
'l10n_diffsource' => array(
'config' => array(
'type' => 'passthrough',
),
),

't3ver_label' => array(
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.versionLabel',
'config' => array(
'type' => 'input',
'size' => 30,
'max' => 255,
)
),

'hidden' => array(
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
'config' => array(
'type' => 'check',
),
),
'starttime' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.starttime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'endtime' => array(
'exclude' => 1,
'l10n_mode' => 'mergeIfNotBlank',
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.endtime',
'config' => array(
'type' => 'input',
'size' => 13,
'max' => 20,
'eval' => 'datetime',
'checkbox' => 0,
'default' => 0,
'range' => array(
'lower' => mktime(0, 0, 0, date('m'), date('d'), date('Y'))
),
),
),
'name' => array(
'exclude' => 1,
'label' => 'LLL:EXT:artikel/Resources/Private/Language/locallang_db.xlf:artikel_domain_model_color.name',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'trim,required'
),
),
'code' => array(
'exclude' => 1,
'label' => 'LLL:EXT:artikel/Resources/Private/Language/locallang_db.xlf:artikel_domain_model_color.code',
'config' => array(
'type' => 'input',
'size' => 4,
'eval' => 'int,required'
)
)
),
);

ext_tables.php

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('artikel_domain_model_color', 'EXT:artikel/Resources/Private/Language/locallang_csh_artikel_domain_model_color.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('artikel_domain_model_color');
$GLOBALS['TCA']['artikel_domain_model_color'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:artikel/Resources/Private/Language/locallang_db.xlf:artikel_domain_model_color',
'label' => 'name',
'label_alt' => 'code',
'label_alt_force' => 1,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'sortby' => 'name',
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'name,code,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/Color.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/artikel_domain_model_color.gif'
),
);

有什么想法为什么会发生这种情况或者我应该从哪里开始调试吗?

最佳答案

正如 Dimitri 所说,sortby 是 TYPO3 用于保存排序信息的表字段的参数。

在线阅读https://docs.typo3.org/typo3cms/TCAReference/7.6/Reference/Ctrl/Index.html#sortby

但是,如果您想按名称等自定义字段对后端的条目进行排序,只需使用default_sortby

在线阅读https://docs.typo3.org/typo3cms/TCAReference/7.6/Reference/Ctrl/Index.html#default-sortby

使用default_sortby,您可以在该表中提供任何 TCA 注册字段。如果您不使用 sortby 字段或不希望后端用户可以手动对条目进行排序,我建议您从参数中完全删除 sortby 。在这种情况下,用于排序的箭头也会在列表中消失,并且不会出现一些误解,为什么可以对 BE 中的条目进行排序而在 FE 中不起作用

关于php - TYPO3:创建新元素时重命名所有实体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43632642/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com