Closed
Description
Expected behavior
When the options provider returns an integer (e.g. Pimcore ID of an object) for value
, for instance: ['key' => 'foobar', 'value' => 1]
:
- Persisted values of multiselect should be the selected options when opening the object.
- Consistent behavior regardless of render type "List" or "Tags".
Actual behavior
- Multiselect (render type "List") has no selected options reflecting the persisted values.
- Render type "List" and "Tags" should behave the same - here only render type "List" is affected.
Steps to reproduce
- Create a DataObject class.
- Add a field of type Multiselect with render type "List" (default).
- Make it a "Dynamic Multiselect" by specifying an options provider (see below). Return valid options according to the docs of "Dynamic Select Typed" in format
['key' => 'foobar', 'value' => 1]
- use an integer for value. - Open the data object, select multiple options and save.
- Reload the object and discover that no option is selected (value is persisted correctly, though).
Possible solutions:
- Specify the option provider option format to always return a string for value and fix the documentation.
- Server-side: Transform/cast the options' values provided by the options provider.
- Client-side
pimcore.object.tags.multiselect
: Cast thevalue
inprepareStoreDataAndFilterLabels()
to string.
Code snippet options provider
<?php
namespace App;
use Pimcore\Model\DataObject;
class MultiOptionsProvider implements DataObject\ClassDefinition\DynamicOptionsProvider\MultiSelectOptionsProviderInterface
{
/**
* @inheritDoc
*/
public function getOptions($context, $fieldDefinition)
{
return [
['key' => 'foo1', 'value' => 1],
['key' => 'foo2', 'value' => 2],
['key' => 'foo3', 'value' => 3],
];
}
/**
* @inheritDoc
*/
public function hasStaticOptions($context, $fieldDefinition)
{
return true;
}
}