23 'title' => __(
'GravityView View',
'gk-gravityview' ),
24 'render_callback' => [ $this,
'render' ],
26 'previewImage' => untrailingslashit( plugin_dir_url( __FILE__ ) ) .
'/preview.svg' 40 static function render( $block_attributes = [] ) {
41 $block_to_shortcode_attributes_map = [
43 'postId' =>
'post_id',
44 'pageSize' =>
'page_size',
45 'sortField' =>
'sort_field',
46 'sortDirection' =>
'sort_direction',
47 'searchField' =>
'search_field',
48 'searchValue' =>
'search_value',
49 'searchOperator' =>
'search_operator',
50 'startDate' =>
'start_date',
51 'endDate' =>
'end_date',
52 'classValue' =>
'class',
54 'singleTitle' =>
'single_title',
55 'backLinkLabel' =>
'back_link_label',
58 if ( isset( $block_attributes[
'searchOperator'] ) && empty( $block_attributes[
'searchValue'] ) ) {
59 unset( $block_attributes[
'searchOperator'] );
62 $shortcode_attributes = [];
64 foreach ( $block_attributes as $attribute =>
$value ) {
67 if ( isset( $block_to_shortcode_attributes_map[ $attribute ] ) && ! empty(
$value ) ) {
68 $shortcode_attributes[] = sprintf(
70 $block_to_shortcode_attributes_map[ $attribute ],
71 str_replace(
'"',
'\"',
$value )
76 $shortcode = sprintf(
'[gravityview %s]', implode(
' ', $shortcode_attributes ) );
78 if (
Arr::get( $block_attributes,
'previewAsShortcode' ) ) {
79 return json_encode( [
'content' => $shortcode,
'script' =>
'',
'styles' =>
'' ] );
84 if ( class_exists(
'GFFormDisplay' ) && defined(
'REST_REQUEST' ) && REST_REQUEST ) {
85 $hooks_js_printed = GFFormDisplay::$hooks_js_printed;
87 GFFormDisplay::$hooks_js_printed =
true;
91 GFFormDisplay::$hooks_js_printed = $hooks_js_printed;
96 if ( ! defined(
'REST_REQUEST' ) || ! REST_REQUEST ) {
97 return $rendered_shortcode[
'content'];
100 return json_encode( $rendered_shortcode );
static render( $block_attributes=[])
Renders [gravityview] shortcode.
static get( $array, $key, $default=null)
{}
modify_block_meta( $block_meta)
Modifies block meta.
static render_shortcode( $shortcode)
Renders shortcode and returns rendered content along with newly enqueued scripts and styles...