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 / name / block.php

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

167 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form Field Name block.
4 *
5 * @package ghostkit
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * Class GhostKit_Form_Field_Name_Block
14 */
15 class GhostKit_Form_Field_Name_Block {
16 /**
17 * GhostKit_Form_Field_Name_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-name',
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__( 'Name', 'ghostkit' ),
40 ),
41 'nameFields' => array(
42 'type' => 'string',
43 'default' => 'first',
44 ),
45
46 'descriptionLast' => array(
47 'type' => 'string',
48 ),
49 'placeholderLast' => array(
50 'type' => 'string',
51 ),
52 'defaultLast' => array(
53 'type' => 'string',
54 ),
55
56 'descriptionMiddle' => array(
57 'type' => 'string',
58 ),
59 'placeholderMiddle' => array(
60 'type' => 'string',
61 ),
62 'defaultMiddle' => array(
63 'type' => 'string',
64 ),
65 )
66 ),
67 )
68 );
69 }
70
71 /**
72 * Register gutenberg block output
73 *
74 * @param array $attributes - block attributes.
75 *
76 * @return string
77 */
78 public function block_render( $attributes ) {
79 $attributes = array_merge(
80 array(
81 'slug' => '',
82 'nameFields' => 'first',
83 'description' => '',
84 'descriptionLast' => '',
85 'placeholderLast' => '',
86 'defaultLast' => '',
87 'descriptionMiddle' => '',
88 'placeholderMiddle' => '',
89 'defaultMiddle' => '',
90 'hideDescription' => false,
91 ),
92 $attributes
93 );
94
95 ob_start();
96
97 $class = 'ghostkit-form-field ghostkit-form-field-name';
98
99 if ( 'first-middle-last' === $attributes['nameFields'] || 'first-last' === $attributes['nameFields'] ) {
100 $class .= ' ghostkit-form-field-name-with-last';
101 }
102 if ( 'first-middle-last' === $attributes['nameFields'] ) {
103 $class .= ' ghostkit-form-field-name-with-middle';
104 }
105
106 if ( isset( $attributes['className'] ) ) {
107 $class .= ' ' . $attributes['className'];
108 }
109
110 $last_attributes = array(
111 'slug' => $attributes['slug'],
112 'slug_sub' => 'last',
113 'description' => $attributes['descriptionLast'],
114 'placeholder' => $attributes['placeholderLast'],
115 'default' => $attributes['defaultLast'],
116 'hideDescription' => $attributes['hideDescription'],
117 );
118
119 $middle_attributes = array(
120 'slug' => $attributes['slug'],
121 'slug_sub' => 'middle',
122 'description' => $attributes['descriptionMiddle'],
123 'placeholder' => $attributes['placeholderMiddle'],
124 'default' => $attributes['defaultMiddle'],
125 'hideDescription' => $attributes['hideDescription'],
126 );
127
128 ?>
129
130 <div class="<?php echo esc_attr( $class ); ?>">
131 <?php GhostKit_Form_Field_Label::get( $attributes ); ?>
132
133 <?php if ( 'first-last' === $attributes['nameFields'] || 'first-middle-last' === $attributes['nameFields'] ) : ?>
134 <div class="ghostkit-form-field-row">
135 <div class="ghostkit-form-field-name-first">
136 <?php endif; ?>
137
138 <input type="text" <?php GhostKit_Form_Field_Attributes::get( $attributes ); ?> />
139
140 <?php GhostKit_Form_Field_Description::get( $attributes ); ?>
141
142 <?php if ( 'first-middle-last' === $attributes['nameFields'] ) : ?>
143 </div>
144 <div class="ghostkit-form-field-name-middle">
145 <input type="text" <?php GhostKit_Form_Field_Attributes::get( $middle_attributes ); ?> />
146
147 <?php GhostKit_Form_Field_Description::get( $middle_attributes ); ?>
148 <?php endif; ?>
149
150 <?php if ( 'first-last' === $attributes['nameFields'] || 'first-middle-last' === $attributes['nameFields'] ) : ?>
151 </div>
152 <div class="ghostkit-form-field-name-last">
153 <input type="text" <?php GhostKit_Form_Field_Attributes::get( $last_attributes ); ?> />
154
155 <?php GhostKit_Form_Field_Description::get( $last_attributes ); ?>
156 </div>
157 </div>
158 <?php endif; ?>
159 </div>
160
161 <?php
162
163 return ob_get_clean();
164 }
165 }
166 new GhostKit_Form_Field_Name_Block();
167