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

[v4] Cannot paste blocks when fieldset is not available #5769

Closed
rasteiner opened this issue Oct 9, 2023 · 0 comments · Fixed by #5779
Closed

[v4] Cannot paste blocks when fieldset is not available #5769

rasteiner opened this issue Oct 9, 2023 · 0 comments · Fixed by #5779
Assignees
Milestone

Comments

@rasteiner
Copy link
Contributor

Description

When trying to paste content into a blocks field which doesn't have all the needed blocks enabled, the following error shows:

Spread syntax requires ...iterable[Symbol.iterator] to be a function

Expected behavior
The available blocks should be pasted.

To reproduce

  1. Blueprint:
fields:
  blocks:
    fieldsets:
      text: blocks/text
  1. Copy this issue (make sure to include the headings)
  2. Paste it into the blocks field
  3. See error

Your setup

Kirby Version
4.0.0 beta 2

Your system (please complete the following information)

  • Device: Desktop PC
  • OS: Windows 11
  • Browser: Chrome
  • Version: 118
  • PHP: 8.2

Additional context
The pasteBlocks function removes unavailable blocks from the parsed input using unset.
unset, however, leaves the key => value association of the remaining entries intact. This creates a sparse array which, when serialized to JSON, gets transformed into an object rather than an array:

{
    "1": { ... }
    "3": { ... }
    "7": { ... }
}

This causes an the error here, when trying to spread that object into the splice function.

Making sure the pasteBlocks function returns a dense array, either by creating a new array and copying available blocks to it (rather than removing unavailable ones), or by creating a new one with return array_values($blocks) seems to sove this issue (there seem to be other issues involving pasting blocks, but I'm unsure if that isn't caused by my particular setup).

@afbora afbora added this to the 4.0.0-beta.3 milestone Oct 11, 2023
@afbora afbora self-assigned this Oct 11, 2023
afbora added a commit that referenced this issue Oct 11, 2023

Verified

This commit was signed with the committer’s verified signature.
pradyunsg Pradyun Gedam
@afbora afbora linked a pull request Oct 11, 2023 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants