PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 2.25.0
Block Animations, Motion & Scroll Effects – Ghost Kit v2.25.0
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / blocks / form / fields / radio / block.php

block.php in Block Animations, Motion & Scroll Effects – Ghost Kit 2.25.0, at gutenberg/blocks/form/fields/radio/block.php

117 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form Field Radio block.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Form_Field_Radio_Block
14 */
15 class GhostKit_Form_Field_Radio_Block {
16 /**
17 * GhostKit_Form_Field_Radio_Block constructor.
18 */
19 public function __construct() {
20 add_action( 'init', array( $this, 'init' ) );
21 }
22
23 /**
24 * Init.
25 */
26 public function init() {
27 if ( ! function_exists( 'register_block_type' ) ) {
28 return;
29 }
30
31 register_block_type(
32 'ghostkit/form-field-radio',
33 array(
34 'parent' => array( 'ghostkit/form' ),
35 'render_callback' => array( $this, 'block_render' ),
36 'attributes' => GhostKit_Form_Field_Attributes::get_block_attributes(
37 array(
38 'label' => array(
39 'default' => esc_html__( 'Radio', 'ghostkit' ),
40 ),
41 'options' => array(
42 'type' => 'array',
43 'items' => array(
44 'type' => 'object',
45 ),
46 ),
47 'inline' => array(
48 'type' => 'boolean',
49 ),
50 )
51 ),
52 )
53 );
54 }
55
56 /**
57 * Register gutenberg block output
58 *
59 * @param array $attributes - block attributes.
60 *
61 * @return string
62 */
63 public function block_render( $attributes ) {
64 $attributes = array_merge(
65 array(
66 'slug' => '',
67 'options' => array(),
68 'inline' => false,
69 ),
70 $attributes
71 );
72
73 ob_start();
74
75 $class = 'ghostkit-form-field ghostkit-form-field-radio';
76
77 if ( $attributes['inline'] ) {
78 $class .= ' ghostkit-form-field-radio-inline';
79 }
80
81 if ( isset( $attributes['className'] ) ) {
82 $class .= ' ' . $attributes['className'];
83 }
84
85 ?>
86
87 <div class="<?php echo esc_attr( $class ); ?>">
88 <?php GhostKit_Form_Field_Label::get( $attributes ); ?>
89
90 <div class="ghostkit-form-field-radio-items">
91 <?php
92 foreach ( $attributes['options'] as $k => $option ) :
93 $item_id = $attributes['slug'] . '-item-' . $k;
94 $item_attrs = array_merge(
95 $attributes,
96 array(
97 'id' => $item_id,
98 )
99 );
100 ?>
101 <label class="ghostkit-form-field-radio-item" for="<?php echo esc_attr( $item_id ); ?>">
102 <input type="radio" <?php checked( $option['selected'] ); ?> value="<?php echo esc_attr( $option['value'] ); ?>" <?php GhostKit_Form_Field_Attributes::get( $item_attrs ); ?> />
103 <?php echo esc_html( $option['label'] ); ?>
104 </label>
105 <?php endforeach; ?>
106 </div>
107
108 <?php GhostKit_Form_Field_Description::get( $attributes ); ?>
109 </div>
110
111 <?php
112
113 return ob_get_clean();
114 }
115 }
116 new GhostKit_Form_Field_Radio_Block();
117