start_controls_section( 'ranq_section', array( 'label' => __( 'Form', '2ranq-forms' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ) ); $this->add_control( 'form_id', array( 'label' => __( 'Which form', '2ranq-forms' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => Ranq_Forms_Elementor::form_options(), 'default' => 0, ) ); $this->add_control( 'ranq_hint', array( 'type' => \Elementor\Controls_Manager::RAW_HTML, 'raw' => sprintf( /* translators: %s: link to the form list. */ __( 'Colours, spacing and shape are set in the form itself, under %s. That way the same form looks the same everywhere it is used.', '2ranq-forms' ), '' . esc_html__( '2ranq Forms', '2ranq-forms' ) . '' ), 'content_classes' => 'elementor-descriptor', ) ); $this->end_controls_section(); } /** * Rendering on the site. * * @return void */ protected function render() { $settings = $this->get_settings_for_display(); $chosen = isset( $settings['form_id'] ) ? (string) $settings['form_id'] : ''; // A `w` in front of the number means the whole section, not only the form. The // same drop down carries both, so the value has to say which is which. if ( 'w' === substr( $chosen, 0, 1 ) ) { // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already cleaned in the field itself. echo Ranq_Forms_Widget::shortcode( array( 'id' => absint( substr( $chosen, 1 ) ) ) ); return; } $form_id = absint( $chosen ); if ( ! $form_id ) { if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) { echo '

' . esc_html__( 'Choose a form in the panel on the left.', '2ranq-forms' ) . '

'; } return; } // It goes through the same path as the shortcode, so the look is the same everywhere. echo Ranq_Forms_Shortcode::render( array( 'id' => $form_id ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already cleaned in the field itself. } }