-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial start for making a Gutenblock for the Contact Form.
At this point it just represents the parent form -- it doesn't handle any fields yet. That will largely depend on how WordPress/gutenberg#3745 progresses.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
add_action( 'init', array( 'Grunion_Contact_Form_Gutenblocks', 'register_block_types' ) ); | ||
add_action( 'enqueue_block_editor_assets', array( 'Grunion_Contact_Form_Gutenblocks', 'enqueue_block_editor_assets' ) ); | ||
|
||
class Grunion_Contact_Form_Gutenblocks { | ||
|
||
public static function register_block_types() { | ||
register_block_type( 'jetpack/contact-form', array( | ||
'render_callback' => array( __CLASS__, 'render_contact_form' ), | ||
) ); | ||
|
||
// Stubbed out for now until nested blocks are in. | ||
register_block_type( 'jetpack/contact-field', array( | ||
'render_callback' => array( __CLASS__, 'render_contact_field' ), | ||
) ); | ||
} | ||
|
||
public static function render_contact_form( $args ) { | ||
// return Grunion_Contact_Form::parse( $args ); | ||
return '<pre>' . print_r( $args, true ) . '</pre>'; | ||
} | ||
|
||
// Stubbed out for now until nested blocks are in. | ||
public static function render_contact_field( $args ) {} | ||
|
||
public static function enqueue_block_editor_assets() { | ||
wp_register_script( | ||
'jetpack-contact-form-gutenblocks', | ||
plugins_url( 'js/gutenblocks.js', __FILE__ ), | ||
array( 'wp-blocks', 'wp-element' ) | ||
); | ||
wp_enqueue_script( 'jetpack-contact-form-gutenblocks' ); | ||
wp_localize_script( 'jetpack-contact-form-gutenblocks', 'grunionGutenblocks', array( | ||
'strings' => array( | ||
'Contact Form' => __( 'Contact Form', 'jetpack' ), | ||
'What would you like the subject of the email to be?' => | ||
__( 'What would you like the subject of the email to be?', 'jetpack' ), | ||
'Which email address should we send the submissions to?' => | ||
__( 'Which email address should we send the submissions to?', 'jetpack' ), | ||
), | ||
) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
( function( wp, strings ) { | ||
wp.blocks.registerBlockType( 'jetpack/contact-form', { | ||
title : strings['Contact Form'], | ||
icon : 'feedback', | ||
category : 'common', | ||
|
||
attributes : { | ||
subject : { | ||
type : 'string', | ||
default : '' | ||
}, | ||
to : { | ||
type : 'string', | ||
default : '' | ||
} | ||
}, | ||
|
||
edit : function( props ) { | ||
function handleSubjectChange( value ) { | ||
props.setAttributes({ | ||
subject : value | ||
}); | ||
return value; | ||
} | ||
function handleToChange( value ) { | ||
props.setAttributes({ | ||
to : value | ||
}); | ||
return value; | ||
} | ||
|
||
return [ | ||
wp.element.createElement( | ||
'h1', | ||
{ | ||
key : 'jetpack/contact-form/placeholder', | ||
}, | ||
'This is a Placeholder.' | ||
), | ||
!! props.focus && wp.element.createElement( | ||
wp.blocks.InspectorControls, | ||
{ key : 'inspector' }, | ||
[ | ||
wp.element.createElement( | ||
wp.blocks.InspectorControls.TextControl, | ||
{ | ||
key : 'jetpack/contact-form/inspector/subject', | ||
onChange : handleSubjectChange, | ||
value : props.attributes.subject, | ||
label : strings['What would you like the subject of the email to be?'] | ||
} | ||
), | ||
wp.element.createElement( | ||
wp.blocks.InspectorControls.TextControl, | ||
{ | ||
key : 'jetpack/contact-form/inspector/to', | ||
onChange : handleToChange, | ||
value : props.attributes.to, | ||
label : strings['Which email address should we send the submissions to?'], | ||
help : 'Help for to line whatever' | ||
} | ||
) | ||
] | ||
), | ||
]; | ||
}, | ||
|
||
save : function() { | ||
return null; | ||
} | ||
|
||
} ); | ||
} )( window.wp, window.grunionGutenblocks.strings ); |