renderPreview( $block, $content, $postId );
} else {
$this->render( $block, $content, $postId );
}
}
protected function renderPreview( $block, $content, $postId ) {
print '';
$previewPost = $this->getPreviewPost( $postId );
$postId = $previewPost->ID;
$this->render( $block, $content, $postId );
}
protected function render( $block, $content, $postId ) {
// open slider tags
print '
';
print '
';
print '
';
// set inner blocks that were parsed from block already before calling render_block()
$innerBlocks = $GLOBALS['acfg_loop_inner_blocks'];
if( !$innerBlocks ) {
$editorPostId = intval( acf_maybe_get_POST( 'post_id' ) );
$editorPost = get_post( $editorPostId );
$editorPostContent = $editorPost->post_content;
$editorPostBlocks = parse_blocks( $editorPostContent );
foreach ( $editorPostBlocks as $block ) {
if( 'acf/acfg-acf-repeater-gallery' == $block['blockName'] ) {
$innerBlocks = $block['innerBlocks'];
}
}
}
// get the field key and load field object
$repeaterFieldKey = get_field( 'meta_key' );
$repeaterFieldObject = get_field_object( $repeaterFieldKey, $postId );
// arrange subfields by name so they can be referenced
$subfieldsOriginal = $repeaterFieldObject['sub_fields'];
$subfieldsKeyed = [];
foreach( $subfieldsOriginal as $subfield ) {
$subfieldsKeyed[ $subfield['name'] ] = $subfield;
}
while ( have_rows( $repeaterFieldObject['key'], $postId )) :
the_row();
print '- ';
foreach( $innerBlocks as $block ) {
$metaKey = $block['attrs']['data']['meta_key'];
$subfieldValue = get_sub_field( $subfieldsKeyed[$metaKey]['key'] );
$GLOBALS['acfg_loop_field_value'] = $subfieldValue;
print render_block( $block );
}
print '
';
endwhile;
// closing slider tags
print '
';
print '';
}
}