# weforms/1.3.8/includes/admin/class-gutenblock.php

weForms – Easy Drag &amp; Drop Contact Form Builder For WordPress, version 1.3.8. 113 lines.

- Page: https://pluginprobe.com/plugins/weforms/1.3.8/code/includes/admin/class-gutenblock.php
- Raw: https://pluginprobe.com/plugins/weforms/1.3.8/raw/includes/admin/class-gutenblock.php
- Modified: 2019-04-11T12:08:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/weforms/1.3.8/code/includes/admin/class-gutenblock.php#L10-L20`.

```php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
/**
 * Adds weForms block
 */
class weForms_FormBlock {
    /**
     * Register widget with WordPress.
     */
    public function __construct() {
        //add_action( 'weforms_loaded', array($this, 'weforms_block_load' ) );
        // wait for Gutenberg to enqueue it's block assets
        add_action( 'enqueue_block_editor_assets', array ( $this, 'weforms_form_block' ) );
        // load the preview information and form
        add_action( 'wp_head', array( $this, 'load_preview_data' ) );
    }

    function weforms_form_block() {
        $js_dir  = WEFORMS_ASSET_URI . '/js/';
        $css_dir = WEFORMS_ASSET_URI . '/css/';

        // Once we have Gutenberg block javascript, we can enqueue our assets
        wp_register_script(
            'weforms-forms-block',
            $js_dir . 'gutenblock.js',
            array( 'wp-blocks', 'wp-editor', 'wp-components', 'wp-i18n', 'wp-element', 'underscore' )
        );

        wp_register_style(
            'weforms-forms-block-style',
            $css_dir . 'gutenblock.css',
            array( 'wp-edit-blocks' )
        );
        wp_register_style(
            'weforms-forms-block-editor',
            $css_dir . 'gutenblock-editor.css',
            array( 'wp-edit-blocks', 'form-blocks-style' )
        );

        /**
         * we need to get our forms so that the block can build a dropdown
         * with the forms
         * */
        wp_enqueue_script( 'weforms-forms-block' );

        $forms      = array();
        $all_forms  = weforms()->form->all();

        foreach( $all_forms['forms'] as $form ){
            $forms[] = array (
                'value' => $form->id,
                'label' => $form->name,
            );
        }

        $block_logo     = WEFORMS_ASSET_URI . '/images/icon-weforms.png';
        $thumbnail_logo = WEFORMS_ASSET_URI . '/images/icon-weforms.png';

        wp_localize_script( 'weforms-forms-block', 'weFormsBlock', array(
            'forms'          => $forms,
            'siteUrl'        => get_site_url(),
            'block_logo'     => $block_logo,
            'thumbnail_logo' => $thumbnail_logo
        ) );
        wp_enqueue_style( 'weforms-forms-block-style' );
        wp_enqueue_style( 'weforms-forms-block-editor' );
    }

    public function load_preview_data() {
        $js_dir  = WEFORMS_ASSET_URI . '/js/';

        // check for preview and iframe get parameters
        if( isset( $_GET[ 'weforms_preview' ] ) && isset( $_GET[ 'weforms_iframe' ] ) ){
            $form_id = intval( $_GET[ 'weforms_preview' ] );
            // Style below: update width and height for particular form
            ?>
            <style media="screen">
                #wpadminbar {
                    display: none;
                }
                header,
                footer{
                    display: none;
                }

                .wpuf-form-add {
                    z-index: 9001;
                    position: fixed;
                    top: 0;
                    left: 0;
                    width: 100vw;
                    height: 100vh;
                    background-color: white;
                    display: block !important;
                }

            </style>
            <?php

            // register our script to target the form iFrame in page builder
            wp_register_script(
                'weforms-block-setup',
                $js_dir . 'blockFrameSetup.js',
                array( 'underscore', 'jquery' )
            );

            wp_localize_script( 'weforms-block-setup', 'weFormsBlockSetup', array(
                'form_id' => $form_id
            ) );

            wp_enqueue_script( 'weforms-block-setup' );
        }
    }
}
```
