Finder list - grouped array

I have the same preset for multiple items … but the listing returns the entire field from grouped. How do I get a duplicate value for items that have the same preset?

        $ContentPresetPhone = $this->SettingsCountries->find('list', [
            'keyField' => 'preset',
            'valueField' => function ($item) {
                return $item->get('presetPhone');
            },
        ]);

Result should be:

<select>
    <option value="1">+1 - USA</option>
    <option value="1">+1 - Virgin Islands</option>
    <option value="685">+685 - Western Samoa</option>
    <option value="967">+967 - Yemen</option>
</select>

Thank you

Php array doesn’t like two or more same keys. Make you query manually and run foreach to generate inputs.

1 Like

why not simply try 'keyField' => 'id',
Then you have the ID of the SettingsCountry ID which is definitely unique

Yes, but will it translate into value? I need to have a preset value there.

Not automatically but you you can easily get the data from the passed id like so

$entity = $this->SettingsCountries->get($passed_id);
$preset = $entity->preset;
1 Like