[TYPO3-english] Typo3 foreign_table: How to specify a specific column to a select drop down menu?

Mikel lists at con-version.com
Wed Oct 25 16:38:09 CEST 2017


OK. Yes, that is possible. Like I said —> itemsProcFunc.

Go into your tca, to the select field.
'renderType' => 'selectSingle',
'foreign_table' => 'tx_cvfoobar_domain_model_kunde',
'itemsProcFunc' => ‚Foobar\CvFoobar\Tca\SelectProcFunc->prepareItems',

class SelectProcFunc
{

   public function prepareItems($param) {
      $newItems = [];
      foreach ($param['items'] as $item) {
         $newItem = [
            0 => 'Enter your label',
            1 => 'enter_your_value'
         ];
         $newItems[] = $newItem;
      }
      $param['items'] = $newItems;
      return $param;
   }

}

Just as a quick example. That inserts only static values and labels.
To get more information from related Kunde record, you need to make an instance of the repository and load the record by uid. 
You need to allow string inserts, if kundeuid is just a string.

BUT: This is not a very safe solution. You write the values into the database. What happens, if a user changes the kundeuid in one of the records? The relation is broken, as the value has been written into the database.
Also, for db queries, you need to compare strings. You also need to evaluate, that kundeuid is unique (if needed).

What is your target? Do you want to group records by that attribute „kundeuid“? If so, you should better add another model „Kundengruppe“ with m:n relations to Appliance and Kunde. This also would make db queries more easy, as you can build queries from both sides and get your Appliance by Kundengruppe and also your Kunden by Kundengruppe.

Mikel


More information about the TYPO3-english mailing list