Block editor not showing saved content.

In my app i have a product model with the HasBlocks trait and a product repository with the HandleBlocks trait. For some reason the blockeditor is always empty when i visit it. but the data for it is present in the database. am i forgetting a step ?
class Product extends Model implements Sortable
{
use HasBlocks, HasFactory, HasFiles, HasMedias, HasNesting, HasPosition, HasRevisions, HasSlug, HasTranslation;
//... rest of the code (cant inlcude it becouse of character limitation)
}
class Product extends Model implements Sortable
{
use HasBlocks, HasFactory, HasFiles, HasMedias, HasNesting, HasPosition, HasRevisions, HasSlug, HasTranslation;
//... rest of the code (cant inlcude it becouse of character limitation)
}
class ProductRepository extends ModuleRepository
{
use HandleBlocks, HandleFiles, HandleMedias, HandleNesting, HandleRevisions, HandleSlugs, HandleTranslations;
//... rest of the code (cant inlcude it becouse of character limitation)
}
class ProductRepository extends ModuleRepository
{
use HandleBlocks, HandleFiles, HandleMedias, HandleNesting, HandleRevisions, HandleSlugs, HandleTranslations;
//... rest of the code (cant inlcude it becouse of character limitation)
}
No description
No description
11 Replies
zeezo887
zeezo8873mo ago
Hi @kwatman what version of twill is this happening? and would you be able to share a reproduction?
kwatman
kwatmanOP3mo ago
Im using twill 3.3.1. cant share all of the code of the project as its is confidential. But i have by now some more information that i found while trying to debug this. i dumped the fields that get loaded in the repository and it looks like this:
array:17 [// app/Repositories/ProductRepository.php:30
"id" => 1
"deleted_at" => null
"created_at" => "2024-08-20T13:32:41.000000Z"
"updated_at" => "2024-08-20T14:10:22.000000Z"
"published" => 1
"position" => 1
"sellable" => 7
"hero_button_visible" => 0
"hero_button_type" => "page"
"hero_button_link" => null
"_lft" => 1
"_rgt" => 2
"parent_id" => null
"blocks" => null
//...
]
array:17 [// app/Repositories/ProductRepository.php:30
"id" => 1
"deleted_at" => null
"created_at" => "2024-08-20T13:32:41.000000Z"
"updated_at" => "2024-08-20T14:10:22.000000Z"
"published" => 1
"position" => 1
"sellable" => 7
"hero_button_visible" => 0
"hero_button_type" => "page"
"hero_button_link" => null
"_lft" => 1
"_rgt" => 2
"parent_id" => null
"blocks" => null
//...
]
notice that blocks is null. i also dumped the afterSave fields an they look like this:
array:17 [ // app/Repositories/ProductRepository.php:42
"slug" => array:2 [
"nl" => "boek"
"fr" => null
]
"price" => 20
"vat" => 21
"hero_button_visible" => false
"hero_button_type" => "page"
"cmsSaveType" => "update"
"published" => true
"public" => false
"publish_start_date" => null
"publish_end_date" => null
"parent_id" => 0
"medias" => null
"browsers" => null
"blocks" => array:1 [
0 => array:8 [
"id" => 1724223025886
"type" => "a17-block-app-contact"
"is_repeater" => false
"editor_name" => "default"
"content" => array:1 [
"title" => array:1 [
"nl" => "test"
]
]
"medias" => []
"browsers" => []
"blocks" => []
]
]
//...
]
array:17 [ // app/Repositories/ProductRepository.php:42
"slug" => array:2 [
"nl" => "boek"
"fr" => null
]
"price" => 20
"vat" => 21
"hero_button_visible" => false
"hero_button_type" => "page"
"cmsSaveType" => "update"
"published" => true
"public" => false
"publish_start_date" => null
"publish_end_date" => null
"parent_id" => 0
"medias" => null
"browsers" => null
"blocks" => array:1 [
0 => array:8 [
"id" => 1724223025886
"type" => "a17-block-app-contact"
"is_repeater" => false
"editor_name" => "default"
"content" => array:1 [
"title" => array:1 [
"nl" => "test"
]
]
"medias" => []
"browsers" => []
"blocks" => []
]
]
//...
]
here blocks is filled in. i also found 2 queries in the laravel debugger to twill_blocks. I tried debuggin these queries to see what they return. when running select * from twill_blocks I get all the blocks. But when running select * from twill_blocks where twill_blocks.blockable_type = 'App\Models\Product' it does not return anything. im sorry that i cant share anything reproducible but i hope you can help me further with this info.
No description
No description
No description
No description
kwatman
kwatmanOP3mo ago
dont know what i did but now the blocks are loaded in the getFormFields dump in the repository. however they still dont show in the editor
No description
No description
zeezo887
zeezo8873mo ago
Okay, it's hard to figure out the problem without a reproduction but let's see if the blocks are getting to the frontend. Can you tell me the value of TWILL.STORE.form.blocks in your browser console?
kwatman
kwatmanOP3mo ago
this is what it shows. clicked some of the values open. any value in particular you need to see ?
No description
zeezo887
zeezo8873mo ago
Yeah, the blocks are not getting to the FE. You should have the default editor values in the result
No description
kwatman
kwatmanOP3mo ago
So if undersatnd it correctly then the blocks get passed to the page but it does not laod them in the javascript object. is there somthing that happens between these steps ? i was not to original developer of this project so maybe the original developer hooked into a step that happens during the loading of the page and does something there that fucks it up? is that possible in twill ? after checking i see that this happens everywhere on the site where a block editor is used. not just with the product model i made
zeezo887
zeezo8873mo ago
The blocks might not have been passed, what you can do is get into the edit method in the ModuleController and dump $this->form($id). Then check the form_fields to see the value of blocks.
kwatman
kwatmanOP3mo ago
blocks has values in the dump.
No description
zeezo887
zeezo8873mo ago
Then, somehow, the blocks are not passed to the frontend. I would suggest you reinstall twill or check out the render method of vendor/area17/twill/src/View/Components/Fields/BlockEditor.php and the _block_editor view file. I can't reproduce this issue
kwatman
kwatmanOP3mo ago
i found it. i checked the _block_editor.blade.php file and it looked like this:
@unless($withoutSeparator)
<hr/>
@endunless

<a17-blocks title="{{ $label }}"
@if ($renderForBlocks) :editor-name="nestedEditorName('{{ $name }}')" @else editor-name="{{ $name }}" @endif
trigger="{{ $trigger }}" :is-settings="{{ (bool) $isSettings ? 'true' : 'false' }}">
</a17-blocks>

@push('extra_css')
<style>
.editorPreview__item {
min-height: 30px !important;
}

</style>
@endpush

@push('vuexStore')
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $name }}'] =
{!! json_encode(array_values($allowedBlocks)) !!}
window['{{ config('twill.js_namespace') }}'].STORE.form.editorNames.push({!! json_encode($editorName) !!})
@endpush

@pushonce('vuexStore:block_editor')
@include('twill::partials.form.utils._block_editor_store')
@endpushonce
@unless($withoutSeparator)
<hr/>
@endunless

<a17-blocks title="{{ $label }}"
@if ($renderForBlocks) :editor-name="nestedEditorName('{{ $name }}')" @else editor-name="{{ $name }}" @endif
trigger="{{ $trigger }}" :is-settings="{{ (bool) $isSettings ? 'true' : 'false' }}">
</a17-blocks>

@push('extra_css')
<style>
.editorPreview__item {
min-height: 30px !important;
}

</style>
@endpush

@push('vuexStore')
window['{{ config('twill.js_namespace') }}'].STORE.form.availableBlocks['{{ $name }}'] =
{!! json_encode(array_values($allowedBlocks)) !!}
window['{{ config('twill.js_namespace') }}'].STORE.form.editorNames.push({!! json_encode($editorName) !!})
@endpush

@pushonce('vuexStore:block_editor')
@include('twill::partials.form.utils._block_editor_store')
@endpushonce
looking in the twill source code i could see that the last aprt needed to be:
@pushOnce('vuexStore', 'form:block_editor')
@include('twill::partials.form.utils._block_editor_store')
@endPushOnce
@pushOnce('vuexStore', 'form:block_editor')
@include('twill::partials.form.utils._block_editor_store')
@endPushOnce
change it back to that fixed the issue. looks like the dev before me made some changes to the file. thanks for all the help @zeezo887 .
Want results from more Discord servers?
Add your server