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

时间:2017-04-26 11:16:33

标签: php typo3 extbase typo3-6.2.x

我创建了一个在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'
),
);

为什么会发生这种情况或我应该开始调试的任何想法?

2 个答案:

答案 0 :(得分:4)

正如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中排序而没有效果

答案 1 :(得分:2)

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