PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
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 years ago choices-field-render.php 2 years ago
choice-render.php
116 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 = $this->has_choice_input()
51 ? array()
52 : array(
53 'aria-checked' => $is_checked ? 'true' : 'false',
54 'role' => $this->block_type->is_allowed_multiple() ? 'checkbox' : 'radio',
55 'tabindex' => '0',
56 );
57
58 $attrs = get_block_wrapper_attributes(
59 array_merge(
60 array(
61 'class' => 'jet-form-builder-choice--item' . ( $is_checked ? ' is-checked' : '' ),
62 ),
63 $accessibility_attrs
64 )
65 );
66
67 return sprintf(
68 '<li %1$s>%2$s</li>',
69 $attrs,
70 ( $this->block_type->block_content .
71 ( $this->has_choice_control() ? '' : $this->get_hidden_input_control() )
72 )
73 );
74 }
75
76 public function get_hidden_input_control(): string {
77 /**
78 * Cannot delete this row.
79 * Although this input will be hidden and has no LABEL, if it is not done,
80 * the availability of other LABEL elements will be broken
81 */
82 $this->block_type->get_field_id( '', 'label' );
83
84 return Choice_Control_Render::get_input_control(
85 $this->block_type,
86 array(
87 array( 'style', 'display:none;' ),
88 )
89 );
90 }
91
92 public function has_choice_control(): bool {
93 return $this->choice_control_exist;
94 }
95
96 public function has_choice_input(): bool {
97 return $this->choice_input_exist;
98 }
99
100 protected function set_choice_check( array $wp_block ) {
101 if ( empty( $wp_block['innerBlocks'] ) ) {
102 return;
103 }
104
105 $control = Block_Helper::find_by_block_name(
106 $wp_block['innerBlocks'],
107 'jet-forms/choice-control'
108 );
109
110 if ( $control ) {
111 $this->choice_control_exist = true;
112 $this->choice_input_exist = empty( $control['attrs']['control_type'] );
113 }
114 }
115 }
116