GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
view-details/block.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class ViewDetails {
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 View Details', '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 [gravityview] 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  'viewId' => 'id',
42  'detail' => 'detail',
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( '[gravityview %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 }
static render( $block_attributes=[])
Renders [gravityview] shortcode.
static get( $array, $key, $default=null)
{}
Definition: Arr.php:99
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...