array( $this, 'render' ), ) ); if ( is_admin() && current_user_can( Plugin::capability() ) ) { add_action( 'enqueue_block_editor_assets', array( $this, 'editor_data' ) ); } } /** * Give the editor a list of forms and the preview stylesheet. */ public function editor_data() { $forms = array(); foreach ( FormRepository::query( array( 'per_page' => 100 ) )['items'] as $form ) { $forms[] = array( 'id' => $form['id'], 'title' => $form['title'], 'status' => $form['status'], ); } wp_add_inline_script( 'fillaro-block', 'window.fillaroBlock = ' . wp_json_encode( array( 'forms' => $forms, 'adminUrl' => admin_url( 'admin.php?page=fillaro' ), ) ) . ';', 'before' ); } /** * Server render. * * @param array $attributes Block attributes. * @return string */ public function render( $attributes ) { $id = isset( $attributes['formId'] ) ? absint( $attributes['formId'] ) : 0; if ( ! $id ) { return ''; } return FormRenderer::render( $id ); } }