Typo3 foreign_table & foreign_table_where in TCA

I am struggling with the following problem.

I have two database tables: Books and Category. I get all the data from the "books" -table through the Sysfolder in the Backend List-view for editing, sorting and managing it.

What I would like to receive is that this list will also indicate the name of the category in which the book is located.

In the "Books" table there is a field "external-key" "category_id" , which determines which category the book belongs to. I tried using this "category_id" to get the category name in the List-view from books.

When I define in TCA['books'] that category_id like:

 'category_id' => array ( 'exclude' => 0, 'label' => 'Cat name', 'config' => array ( 'type' => 'select', 'foreign_table' => 'category', 'foreign_table_where' => 'AND category.id=###REC_FIELD_category_id###', 'eval' => 'int', 'checkbox' => '0', 'default' => 0 ) ), 

it connects books and categories using category_id (in a table book) and uid (in a category table).

Not as I would like to link them using category_id (in the Books-table) and id (in the Category table). This id is a category identifier and may differ from uid.

Am I doing something wrong or is Typo3 somehow automatically doing this "join" with foreign uid tables.? Is there any way to get it as I would like?

+6
source share
2 answers

I am afraid that it is not possible to specify a different foreign key. Therefore, if someone does not prove to me that I am wrong, here is a workaround that I would use.

itemsProcFunc type select allows you to completely redefine items in the menu and, thus, create a different relationship.

  • Create an additional class that will be loaded only in the backend, and it will have a method that will be called in itemsProcFunc :

    yourMethod($PA, $fobj)

  • Make a method to load all the categories that you want in the SELECT field and set them to $PA['items'] , completely redefining it so that it is an array of arrays, where key 0 is the title of the element and 1 is the identifier categories you want. See items in select .

    $PA['items'] = array(array($title, $id, ''));

  • Include the class in ext_tables.php :

    if(TYPO3_MODE == 'BE') require_once(t3lib_extMgm::extPath($_EXTKEY).'class.YOUR_CLASS.php');

  • Define the category field in the book table:

    'itemsProcFunc' => 'tx_YOUR_CLASS->yourMethod',

+3
source

In addition to the big answer cascaval: @cascaval: Do you mind pointing to select.items in Typo3TCA in the selected links? Current links are not direct.

http://docs.typo3.org/typo3cms/TCAReference/singlehtml/#columns-select-properties-items

(there is no permission to comment on your answer, so I had to answer to myself only for this link ... strange)

0
source

Source: https://habr.com/ru/post/910936/


All Articles