• Resolved Shaun Robinson

    (@rubious)


    This doesn’t seem to work with Gutenberg, using ACF Gutenberg blocks?

    When you save the page, the table data is all lost.

    Any plans to fix this please?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Johann Heyne

    (@jonua)

    Hi Shaun,

    the current version of the table plugin has no Gutenberg block support yet, but the next version (1.3) will support blocks. The ACF version 5.8, which introduces the blocks, is still in beta and I´m still testing the block functionalities for a few days.

    Cheers,
    Johann

    Plugin Author Johann Heyne

    (@jonua)

    Here is the latest version supporting the ACF Gutenberg blocks for beta testing.
    https://downloads.wordpress.org/plugin/advanced-custom-fields-table-field.1.3.1.zip

    Plugin Author Johann Heyne

    (@jonua)

    Here is the Beta2 version supporting the ACF Gutenberg blocks. Fixes an encoding issue.
    https://downloads.wordpress.org/plugin/advanced-custom-fields-table-field.1.3.1-beta2.zip

    Thanks

    This seems to be broken – after creating a table and saving it, you can no longer edit it.

    Plugin Author Johann Heyne

    (@jonua)

    Thanks. The 1.3.1-beta2.zip should work together with ACF 5.8.0-beta3.

    That’s the one we’re using – strange.

    Plugin Author Johann Heyne

    (@jonua)

    I just created a ACF Block like code below and assigned a table field with name “table”. In the Gutenberg editor I can add the block with the table field, can add table content in the aside panel, changes appears in the block preview, can switch to edit the fields in the block itself, table content is still current. After saving the page I can select the table block and still edit its table in the aside, I can reload the page and the table content is still there.

    My basic code for functions.php is…

    add_action( 'acf/init', function() {
    
        if( function_exists('acf_register_block') ) {
    
            acf_register_block(array(
                'name' => 'acf-table',
                'title' => __('ACF Table'),
                'description' => __('A custom table block.'),
                'render_callback' => function( $block ) {
    
                    echo '<p>Table Example</p>';
    
                    $table = get_field( 'table' );
                    echo render_table( $table );
    
                },
                'category' => 'formatting',
                'icon' => 'editor-table',
                'keywords' => array( 'table' ),
            ));
        }
    });
    
    if ( ! function_exists('render_table') ) {
    
        function render_table( $data = false ) {
    
            $return = '';
    
            if ( $data ) {
    
                $return .= '<table border="1">';
    
                    if ( ! empty( $data['caption'] ) ) {
    
                        $return .= '<caption>' . $data['caption'] . '</caption>';
                    }
    
                    if ( isset( $data['header'] ) and is_array( $data['header'] ) ) {
    
                        $return .= '<thead>';
    
                            $return .= '<tr>';
    
                                foreach ( $data['header'] as $th ) {
    
                                    $return .= '<th>';
                                        $return .= $th['c'];
                                    $return .= '</th>';
                                }
    
                            $return .= '</tr>';
    
                        $return .= '</thead>';
                    }
    
                    $return .= '<tbody>';
    
                        if ( isset( $data['body'] ) ) {
    
                            foreach ( $data['body'] as $tr ) {
    
                                $return .= '<tr>';
    
                                    foreach ( $tr as $td ) {
    
                                        $return .= '<td>';
                                            $return .= $td['c'];
                                        $return .= '</td>';
                                    }
    
                                $return .= '</tr>';
                            }
                        }
    
                    $return .= '</tbody>';
    
                $return .= '</table>';
            }
    
            return $return;
        }
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Gutenberg?’ is closed to new replies.