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

TYPO3: Renaming of alle entities on creation of a new element

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

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

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

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

型号:

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

知道为什么会发生这种情况或我应该从哪里开始调试吗?

ext_tables.php 的 TCA 中删除 'sortby' => 'name',。排序字段是一个整数字段,由 Typo3 自动更新,它不应该是用户可编辑的文本字段

正如 Dimitri 所说,sortby 是 table 字段的参数,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,您可以在 table 中提供任何 TCA 注册字段。如果您不使用 sortby 字段或不希望后端用户可以手动对条目进行排序,我建议您从参数中完全删除 sortby。在那种情况下,用于排序的箭头也会在列表中消失,并且不会出现一些误解,为什么可以对 BE 中的条目进行排序而在 FE

中没有影响