PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4.2
3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / advanced-choices / block-renders / choice-render.php
jetformbuilder / modules / advanced-choices / block-renders Last commit date
choice-control-render.php 2 years ago choice-render.php 2 months ago choices-field-render.php 2 months ago
choice-render.php
142 lines
1 <?php
2
3
4 namespace JFB_Modules\Advanced_Choices\Block_Renders;
5
6 // If this file is called directly, abort.
7 use Jet_Form_Builder\Blocks\Block_Helper;
8 use Jet_Form_Builder\Blocks\Render\Base;
9 use JFB_Modules\Advanced_Choices\Block_Types\Choice;
10
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 /**
16 * @property Choice $block_type
17 *
18 * Class Choice_Render
19 * @package Jet_Form_Builder\Blocks\Render
20 */
21 class Choice_Render extends Base {
22
23 /**
24 * Contains the jet-forms/choice-control block or not.
25 *
26 * Affects whether or not to add a hidden field
27 *
28 * @var bool
29 */
30 protected $choice_control_exist = false;
31
32 /**
33 * Contains a jet-forms/choice-control block with a default type control.
34 * That is, a normal input instead of a picture
35 *
36 * Affects whether to make this block accessible
37 *
38 * @var bool
39 */
40 protected $choice_input_exist = false;
41
42 public function get_name() {
43 return 'choice';
44 }
45
46 public function render( $wp_block = null, $template = null ) {
47 $this->set_choice_check( $wp_block );
48 $is_checked = $this->block_type->is_checked_current();
49
50 $accessibility_attrs = array(
51 'aria-checked' => $is_checked ? 'true' : 'false',
52 'role' => $this->block_type->is_allowed_multiple() ? 'checkbox' : 'radio',
53 'tabindex' => '0',
54 );
55
56 $choice_attrs = array(
57 'class' => 'jet-form-builder-choice--item' . ( $is_checked ? ' is-checked' : '' ),
58 );
59
60 $fixed_width_style = $this->get_fixed_width_style();
61
62 if ( $fixed_width_style ) {
63 $choice_attrs['style'] = $fixed_width_style;
64 }
65
66 $attrs = get_block_wrapper_attributes(
67 array_merge(
68 $choice_attrs,
69 $accessibility_attrs
70 )
71 );
72
73 return sprintf(
74 '<li %1$s>%2$s</li>',
75 $attrs,
76 ( $this->block_type->block_content .
77 ( $this->has_choice_control() ? '' : $this->get_hidden_input_control() )
78 )
79 );
80 }
81
82 protected function get_fixed_width_style(): string {
83 $layout = $this->block_type->block_attrs['style']['layout'] ?? array();
84
85 if (
86 empty( $layout['selfStretch'] ) ||
87 'fixed' !== $layout['selfStretch'] ||
88 empty( $layout['flexSize'] )
89 ) {
90 return '';
91 }
92
93 return safecss_filter_attr(
94 sprintf(
95 'flex-basis:auto;width:%s;',
96 $layout['flexSize']
97 )
98 );
99 }
100
101 public function get_hidden_input_control(): string {
102 /**
103 * Cannot delete this row.
104 * Although this input will be hidden and has no LABEL, if it is not done,
105 * the availability of other LABEL elements will be broken
106 */
107 $this->block_type->get_field_id( '', 'label' );
108
109 return Choice_Control_Render::get_input_control(
110 $this->block_type,
111 array(
112 array( 'style', 'display:none;' ),
113 array( 'aria-label', 'advanced choice hidden input' ),
114 )
115 );
116 }
117
118 public function has_choice_control(): bool {
119 return $this->choice_control_exist;
120 }
121
122 public function has_choice_input(): bool {
123 return $this->choice_input_exist;
124 }
125
126 protected function set_choice_check( array $wp_block ) {
127 if ( empty( $wp_block['innerBlocks'] ) ) {
128 return;
129 }
130
131 $control = Block_Helper::find_by_block_name(
132 $wp_block['innerBlocks'],
133 'jet-forms/choice-control'
134 );
135
136 if ( $control ) {
137 $this->choice_control_exist = true;
138 $this->choice_input_exist = empty( $control['attrs']['control_type'] );
139 }
140 }
141 }
142