monsieurbiz / SyliusRichEditorPlugin

This plugin add a rich editor on fields to be able to drag and drop elements and edit it.
MIT License
65 stars 35 forks source link

Fix array keys of an element type collection #192

Closed hussonkevin closed 1 year ago

hussonkevin commented 1 year ago

When you get an element with form type CollectionType and you create 3 items, you'll get the following indices [0 => data, 1 => data, 2 => data] If you remove the index 1 then you get the following indices [0 => data, 2 => data] When you save the page, all elements are saved into json object but the format of this sub element is converted into object instead of array. To fix that you need to apply array_values() to reset keys. This function cannot be applied on a Form Event because you override form data with the request into this method processFormDataWithoutChild due to this:

if ($form->getConfig()->getType()->getInnerType() instanceof NativeFileType && !empty($requestData)) {
    // Check if we have a string value for this fields which is the file path (During edition for example)
    return $requestData; // Will return the current filename string
}
maximehuran commented 1 year ago

Hi Kevin,

Thank you for your contribution. We know this case and we actually correct it on Sylius directly using this patch : https://github.com/sylius/sylius/pull/13666

But it does not work since Sylius 1.11 and we haven't go another patch at this moment. We had a discussion about this issue before on #174 and we have specific case when indexes are not integer as said @jacquesbh in https://github.com/monsieurbiz/SyliusRichEditorPlugin/pull/174#issuecomment-1054461706