Handles the form charts shortcode.
Description
See also
Parameters
- $atts
-
(array) (Required) Array of shortcode attributes. In addition to the attributes specified here you may pass any arguments that should be forwarded to the respective evaluator.
- 'id'
(int) Form ID. This must always be present. - 'mode'
(string) Slug of the evaluator to use. The evaluator must exist and be enabled for the form. Default is 'element_responses'.
- 'id'
Return
(string) Shortcode output.
Source
File: src/modules/evaluators/module.php
public function get_shortcode_content( $atts ) { $args = $atts; $atts = shortcode_atts( array( 'id' => '', 'mode' => 'element_responses', ), $atts, "{$this->get_prefix()}form_charts" ); $args = array_diff_key( $args, $atts ); $atts['id'] = absint( $atts['id'] ); if ( empty( $atts['id'] ) ) { return __( 'Shortcode is missing a form ID!', 'torro-forms' ); } if ( empty( $atts['mode'] ) ) { return __( 'Shortcode is missing a mode!', 'torro-forms' ); } $form = torro()->forms()->get( $atts['id'] ); if ( ! $form ) { return __( 'Shortcode is using an invalid form ID!', 'torro-forms' ); } $evaluator = $this->get( $atts['mode'] ); if ( is_wp_error( $evaluator ) ) { return __( 'Shortcode is using an invalid mode!', 'torro-forms' ); } if ( ! $evaluator->enabled( $form ) ) { return __( 'Shortcode is using an invalid mode!', 'torro-forms' ); } if ( is_a( $evaluator, Assets_Submodule_Interface::class ) && is_callable( array( $evaluator, 'enqueue_submission_results_assets' ) ) ) { $evaluator->enqueue_submission_results_assets( $this->manager()->assets(), $form ); } $results = $evaluator->evaluate_all( $form ); ob_start(); echo '<div id="' . esc_attr( 'torro-evaluations-results-' . $evaluator->get_slug() ) . '" class="torro-evaluations-results">' . "\n"; $evaluator->show_results( $results, $form, $args ); echo "\n" . '</div>'; $onclick = "var clickedLink=this;Array.from( clickedLink.parentElement.children ).forEach(function(link){clickedLink===link?link.setAttribute('aria-selected','true')||link.parentElement.parentElement.querySelector('#'+link.getAttribute('aria-controls')).setAttribute('aria-hidden','false'):link.setAttribute('aria-selected','false')||link.parentElement.parentElement.querySelector('#'+link.getAttribute('aria-controls')).setAttribute('aria-hidden','true')});return false"; return str_replace( ' class="torro-evaluations-subtab"', ' class="torro-evaluations-subtab" onclick="' . esc_attr( $onclick ) . '"', ob_get_clean() ); }
Changelog
Version | Description |
---|---|
1.0.0 | Introduced. |