0

I have an extbase extension, where I have a model A with a relation to another model B. Model B has a lot of entries, so I dont want to assign every single value by clicking on it. So it would be nice if I would have a possibility to somehow select all entries.

I tried to do this like in the page settings the "Usergroup Accsess Rights" area (http://docs.typo3.org/typo3cms/TCAReference/Reference/Columns/Select/Index.html#columns-select-examples-multiple). To have mixed values (static and dynamic) the field has to be a CSV field. I use an itemsProcFunc, where i build my array and put the static value in. The "All Entries" entry has a -1 id.

BACKEND FORM OF MODEL A

 Field of modal A           Model B values
 _______________________    _______________________
|All Entries            |  | All Entries           |
|                       |  |-----------------------|
|                       |  | First                 |
|                       |  | Second                |
|                       |  | Third                 |
|                       |  | Fourth                |
|                       |  | ...                   |
|_______________________|  |_______________________|

TCA of Model A for the field of Model B relations

$TCA['tx_myext_domain_model_promotion']['columns']['relToB'] = array(
'exclude' => 0,
'label' => relToB,
'config' => array(
    'type' => 'select',
    'foreign_table' => 'tx_myext_domain_model_modelB',
    'size' => 10,
    'autoSizeMax' => 30,
    'maxitems' => 9999,
    'multiple' => 0,
    'itemsProcFunc' => 'myFunc',
    'exclusiveKeys' => '-1',
),
);

So far so good, this is working now and i get the selected "All Entries" value in my DB. But now the problem is, that the extbase property mapping functionality is broken and I have to write manual SQL everywhere I used this field.

How would you solve this issue? Is there an other way to get the "Select all entries" use case solved?

Daniel
  • 6,916
  • 2
  • 36
  • 47

1 Answers1

0

Personally I would be in favor of a true MM relation instead of comma-separated lists that are considered bad style.

You could go for the following approaches:

  • Add a checkbox to your TCA called e.g. "use all entries". Then use a TCEmain (4.x)/DataHandler (6.x) hook to assign all entries to Model A if this checkbox is checked. On unchecking, remove all of them.
  • Use an itemsProcFunc in the TCA definition to create an own fieldtype that is identical with select, but adds an additional "select all entries" button that adds all entries by JavaScript.

If you need additional information on how to do it, comment the answer and I can elaborate.

lorenz
  • 4,538
  • 1
  • 27
  • 45
  • Thanks for your approaches. I think in both cases I would get a problem when I add new records to Model B because these wouldnt be assigned automatically to my relation. Or is there a way to trigger this? – Banila Dagrov Jan 02 '14 at 14:52
  • Well, you could also use a hook for this and attach a new entry to each record of Model A that has "use all entries" checked. But it sounds hacky to me. I need to give it more thinking. – lorenz Jan 02 '14 at 15:57