1

我正在修改一个图像上传扩展程序,并且我正在开发一个可以将图像放置在类别中的功能。

现在,类别列在一个选择字段中,该字段使用 foreign_table 从表中获取类别(称为 tx_gallery_categories),当保存类别 ID(选项字段中的值)时,将保存到名为 tx_gallery_items 的表中。

但是不再需要该列(我第一次错了)。根据您选择的类别,我希望 TCA 更新名为 tx_gallery_itemsCategory 的表并设置 categoryId,其中 itemId 等于保存的图像 uid

这是 TCA(我已经删除了 categoryId 旁边的所有其他列),我认为 categoryId 是我想从中移出的那个,并进入它自己的连接到 tx_gallery_itemsCategory 的 TCA:

$TCA["tx_gallery_items"] = array (
"ctrl" => $TCA["tx_gallery_items"]["ctrl"],
"interface" => array (
    "showRecordFieldList" => "hidden,oid,filename, videoembedcode,caption"
),
"feInterface" => $TCA["tx_gallery_items"]["feInterface"],
"columns" => array (
    "categoryId" => Array (     
        "exclude" => 1,     
        "label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",       
        "config" => Array (
            "type" => "select",
            "foreign_table" => "tx_gallery_categories",
            // "foreign_table_where" => " true"
            // "itemsProcFunc" => "tx_gallery_getImageCategories->getCategories"
            // 'default' => '123'
        )
    ),
),
"types" => array (
    "0" => array("showitem" => "hidden, oid, filename, categoryId, videoembedcode, caption, linkpid")
)
);

$TCA["tx_gallery_categories"] = array (
"ctrl" => $TCA["tx_gallery_categories"]["ctrl"],
"interface" => array (
    "showRecordFieldList" => "categoryTitle"
),
"feInterface" => $TCA["tx_gallery_categories"]["feInterface"],
"columns" => array (
    "categoryTitle" => Array (      
        "exclude" => 0,     
        "label" => "LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items.categories",       
        "config" => Array (
            "type" => "text",
            "cols" => "30", 
            "rows" => "5",
        )
    )
),
"types" => array (
    "0" => array("showitem" => "categoryTitle")
)

);

但是,我不想像那样工作,而是想将图像 uid 从 tx_gallery_items 保存到另一个名为 tx_gallery_itemsCategory 的表中,该表是 tx_gallery_items 和 tx_gallery_categories 之间的多对多表

以下是表格:

tx_gallery_items:
  uid | pid | ... (and many more but only uid is relevant)
  432 | 34  | ...

tx_gallery_itemsCategory:
  id | itemId | categoryId
  1  | 432    | 1

tx_gallery_categories:
  uid | pid | categoryTitle   
  1   | 34  | example category 

这是 ext_tables.php

$TCA["tx_gallery_items"] = array (
"ctrl" => array (
    'title'     => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
    'label'     => 'filename',
    'tstamp'    => 'tstamp',
    'crdate'    => 'crdate',
    'cruser_id' => 'cruser_id',
    'sortby' => 'sorting',
    'delete' => 'deleted',
    'enablecolumns' => array (
        'disabled' => 'hidden',
    ),
    'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
    'iconfile'          => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
"feInterface" => array (
    "fe_admin_fieldList" => "hidden, oid, filename, category, videoembedcode, caption, linkpid, categoryId",
)
);

$TCA["tx_gallery_categories"] = array (
"ctrl" => array (
    'title'     => 'LLL:EXT:gc_gallery/locallang_db.xml:tx_gallery_items',
    'label'     => 'categoryTitle',
    'tstamp'    => 'tstamp',
    'sortby' => 'sorting',
    'delete' => 'deleted',
    // 'enablecolumns' => array (
        // 'disabled' => 'hidden',
    // ),
    'dynamicConfigFile' => t3lib_extMgm::extPath($_EXTKEY).'tca.php',
    'iconfile'          => t3lib_extMgm::extRelPath($_EXTKEY).'icon_tx_gallery_items.gif',
),
// "feInterface" => array (
    // "fe_admin_fieldList" => "uid, pid, categoryTitle, categoryDescription, tstamp, sorting, deleted, hidden, categorySlug",
// )
);

所以我的问题是(我认为)如何从用户正在编辑的当前图像中获取 uid 并将其保存到另一个表中。

这是我第一次尝试 TCA,我很困惑这一切是如何联系起来的。我希望有人比我更了解这一点:)谢谢。

4

1 回答 1

2

tcemain 组件中实现了钩子概念。processDatamap_postProcessFieldArray当任何记录保存在后端时,都会调用一个调用。因此,您可以检查它是否是“您的”并进行其他查询或您想要更改的任何内容。

有一个如何使用此功能的示例。虽然它已经很老了,但它应该仍然以这种方式工作。

于 2012-06-29T07:17:11.340 回答