GravityView  2.17
The best, easiest way to display Gravity Forms entries on your website.
entry-field/block.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
8 class EntryField {
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 Field', '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 [gvfield] 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' => 'view_id',
42  'entryId' => 'entry_id',
43  'fieldId' => 'field_id',
44  'fieldSettingOverrides' => 'field_setting_overrides',
45  ];
46 
47  $shortcode_attributes = [];
48 
49  foreach ( $block_attributes as $attribute => $value ) {
50  $value = esc_attr( sanitize_text_field( $value ) );
51 
52  if ( isset( $block_to_shortcode_attributes_map[ $attribute ] ) && ! empty( $value ) ) {
53  if ( 'field_setting_overrides' === $attribute ) {
54  $shortcode_attributes[] = $value;
55  } else {
56  $shortcode_attributes[] = sprintf(
57  '%s="%s"',
58  $block_to_shortcode_attributes_map[ $attribute ],
59  str_replace( '"', '\"', $value )
60  );
61  }
62  }
63  }
64 
65  $shortcode = sprintf( '[gvfield %s]', implode( ' ', $shortcode_attributes ) );
66 
67  if ( Arr::get( $block_attributes, 'previewAsShortcode' ) ) {
68  return $shortcode;
69  }
70 
71  $rendered_shortcode = Blocks::render_shortcode( $shortcode );
72 
73  return $rendered_shortcode['content'];
74  }
75 }
static get( $array, $key, $default=null)
{}
Definition: Arr.php:99
modify_block_meta( $block_meta)
Modifies block meta.
static render( $block_attributes=[])
Renders [gvfield] shortcode.
static render_shortcode( $shortcode)
Renders shortcode and returns rendered content along with newly enqueued scripts and styles...