GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
entry/block.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class Entry {
9  /**
10  * Modifies block meta.
11  *
12  * This method is called by class-gv-gutenberg.php before registering the block.
13  *
14  * @since $ver$
15  *
16  * @param array $block_meta
17  *
18  * @return array
19  */
20  public function modify_block_meta( $block_meta ) {
21  return [
22  'title' => __( 'GravityView Entry', 'gk-gravityview' ),
23  'render_callback' => [ $this, 'render' ],
24  'localization' => [
25  'previewImage' => untrailingslashit( plugin_dir_url( __FILE__ ) ) . '/preview.svg'
26  ]
27  ];
28  }
29 
30  /**
31  * Renders [gventry] shortcode.
32  *
33  * @since $ver$
34  *
35  * @param array $block_attributes
36  *
37  * @return string $output
38  */
39  static function render( $block_attributes = [] ) {
40  $block_to_shortcode_attributes_map = [
41  'entryId' => 'id',
42  'viewId' => 'view_id',
43  ];
44 
45  $shortcode_attributes = [];
46 
47  foreach ( $block_attributes as $attribute => $value ) {
48  $value = esc_attr( sanitize_text_field( $value ) );
49 
50  if ( isset( $block_to_shortcode_attributes_map[ $attribute ] ) && ! empty( $value ) ) {
51  $shortcode_attributes[] = sprintf(
52  '%s="%s"',
53  $block_to_shortcode_attributes_map[ $attribute ],
54  str_replace( '"', '\"', $value )
55  );
56  }
57  }
58 
59  $shortcode = sprintf( '[gventry %s]', implode( ' ', $shortcode_attributes ) );
60 
61  if ( Arr::get( $block_attributes, 'previewAsShortcode' ) ) {
62  return $shortcode;
63  }
64 
65  $rendered_shortcode = Blocks::render_shortcode( $shortcode );
66 
67  return $rendered_shortcode['content'];
68  }
69 }
Definition: entry/block.php:8
static get( $array, $key, $default=null)
{}
Definition: Arr.php:99
static render( $block_attributes=[])
Renders [gventry] shortcode.
Definition: entry/block.php:39
modify_block_meta( $block_meta)
Modifies block meta.
Definition: entry/block.php:20
static render_shortcode( $shortcode)
Renders shortcode and returns rendered content along with newly enqueued scripts and styles...