Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Fix BC-Break: Default value on multiselect object type introduced by #15871 #16779

Merged
merged 12 commits into from
Mar 14, 2024
10 changes: 9 additions & 1 deletion models/DataObject/ClassDefinition/Data/Multiselect.php
Expand Up @@ -122,8 +122,16 @@ public function getRenderType(): ?string
return $this->renderType;
}

public function setDefaultValue(array $defaultValue): static
/**
* @return $this
*/
public function setDefaultValue(array|string|null $defaultValue): static
kingjia90 marked this conversation as resolved.
Show resolved Hide resolved
{
if (!$defaultValue) {
$defaultValue = null;
kingjia90 marked this conversation as resolved.
Show resolved Hide resolved
}elseif (is_string($defaultValue)){
$defaultValue = [$defaultValue];
}
Copy link
Contributor

@blankse blankse Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this? When it is null, it must not be changed, Empty Array should also no problem or?

Suggested change
if (!$defaultValue) {
$defaultValue = null;
}elseif (is_string($defaultValue)){
$defaultValue = [$defaultValue];
}
if (is_string($defaultValue)) {
$defaultValue = $defaultValue !== '' ? [$defaultValue] : null;
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My current project has null and "" and somestring values which broke, I would suspect that perhaps some integers could have made it's way into the default value storage as well. Maybe check for scalar values would make it more forgiving?

And for v12.0 create a migration which forces array type for all while making the type stricter again?

Copy link
Contributor

@blankse blankse Mar 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did these defaultValues came from?
Was the field type a single select in the past?
So after the convert in the backend the default value from the single select still exists?

If this is the case, I think we could not make it type strict. This can also possible in v12. We should than also check the case when someone convert the multi select in a single select.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They were created using v6 or v10, some could possibly have been selects or other field types at one point as well.

$this->defaultValue = $defaultValue;

return $this;
Expand Down
Expand Up @@ -18,7 +18,7 @@

use Pimcore\Model\DataObject\ClassDefinition\Data;

interface SelectOptionsProviderInterface
interface SelectOptionsProviderInterface extends MultiSelectOptionsProviderInterface
{
public function getOptions(array $context, Data $fieldDefinition): array;

Expand Down