Skip to content

Commit 2d6d93a

Browse files
committed
Fix Editor templating
1 parent 75ef7e1 commit 2d6d93a

File tree

3 files changed

+5
-23
lines changed

3 files changed

+5
-23
lines changed

README.md

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
### TODO
66

7-
- [ ] Display template content on post creation (right now it's all placeholders)
87
- [ ] Default pattern for created CPT (i.e., render a default single.html content, also save a pattern)
98
- [ ] Document stuff better and show teammates
109
- [ ] Lock all content and styling except bound blocks's inside when entering data

inc/data-entry.php

+5
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ function hydrate_blocks_with_content( $blocks ) {
138138
$content = get_post_meta( get_the_ID(), $binding, true );
139139
}
140140

141+
// If can't find the corresponding content, do not try to inject it.
142+
if ( ! $content ) {
143+
continue;
144+
}
145+
141146
$blocks[ $index ]['innerBlocks'] = parse_blocks( $content );
142147

143148
$blocks[ $index ]['innerHTML'] = inject_content_into_block_markup( $content, $block['innerHTML'] );

inc/data-type-management.php

-22
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function () {
3232
'show_in_menu' => true,
3333
'show_in_rest' => true,
3434
'icon' => 'dashicons-admin-site',
35-
'template' => _convert_parsed_blocks_for_js( parse_blocks( $data_type->template ) ),
3635
)
3736
);
3837

@@ -55,27 +54,6 @@ function () {
5554
0
5655
);
5756

58-
/**
59-
* Converts parsed blocks to a format Gutenberg can understand.
60-
*
61-
* @param array $blocks A list of blocks.
62-
*/
63-
function _convert_parsed_blocks_for_js( $blocks ) {
64-
$template = array();
65-
foreach ( $blocks as $block ) {
66-
if ( null === $block['blockName'] && empty( trim( $block['innerHTML'] ) ) ) {
67-
continue;
68-
}
69-
70-
$entry = array( $block['blockName'], $block['attrs'] );
71-
if ( isset( $block['innerBlocks'] ) && is_array( $block['innerBlocks'] ) ) {
72-
$entry[] = _convert_parsed_blocks_for_js( $block['innerBlocks'] );
73-
}
74-
$template[] = $entry;
75-
}
76-
return $template;
77-
}
78-
7957
/**
8058
* Get all registered data types.
8159
*/

0 commit comments

Comments
 (0)