| @@ -4,8 +4,9 @@ | ||
| 4 | 4 | |
| 5 | 5 | use WPDeveloper\BetterDocs\Editors\Elementor\BaseWidget; |
| 6 | 6 | use Elementor\Controls_Manager; |
| 7 | 7 | use Elementor\Group_Control_Typography; |
| 8 | +use Elementor\Repeater; | |
| 8 | 9 | |
| 9 | 10 | class CodeSnippet extends BaseWidget { |
| 10 | 11 | |
| 11 | 12 | public function get_name() { |
| @@ -74,8 +75,9 @@ | ||
| 74 | 75 | 'php' => __( 'PHP', 'betterdocs' ), |
| 75 | 76 | 'python' => __( 'Python', 'betterdocs' ), |
| 76 | 77 | 'java' => __( 'Java', 'betterdocs' ), |
| 77 | 78 | 'ruby' => __( 'Ruby', 'betterdocs' ), |
| 79 | + 'curl' => __( 'cURL', 'betterdocs' ), | |
| 78 | 80 | 'bash' => __( 'Bash', 'betterdocs' ), |
| 79 | 81 | 'json' => __( 'JSON', 'betterdocs' ), |
| 80 | 82 | 'yaml' => __( 'YAML', 'betterdocs' ), |
| 81 | 83 | 'html' => __( 'HTML', 'betterdocs' ), |
| @@ -93,8 +95,66 @@ | ||
| 93 | 95 | 'description' => __( 'Choose language for syntax highlighting.', 'betterdocs' ), |
| 94 | 96 | ] |
| 95 | 97 | ); |
| 96 | 98 | |
| 99 | + // Additional languages → renders a Mintlify-style language dropdown. | |
| 100 | + $variant_repeater = new Repeater(); | |
| 101 | + | |
| 102 | + $variant_repeater->add_control( | |
| 103 | + 'variant_language', | |
| 104 | + [ | |
| 105 | + 'label' => __( 'Language', 'betterdocs' ), | |
| 106 | + 'type' => Controls_Manager::SELECT, | |
| 107 | + 'default' => 'php', | |
| 108 | + 'options' => [ | |
| 109 | + 'javascript' => __( 'JavaScript', 'betterdocs' ), | |
| 110 | + 'php' => __( 'PHP', 'betterdocs' ), | |
| 111 | + 'python' => __( 'Python', 'betterdocs' ), | |
| 112 | + 'java' => __( 'Java', 'betterdocs' ), | |
| 113 | + 'ruby' => __( 'Ruby', 'betterdocs' ), | |
| 114 | + 'curl' => __( 'cURL', 'betterdocs' ), | |
| 115 | + 'bash' => __( 'Bash', 'betterdocs' ), | |
| 116 | + 'json' => __( 'JSON', 'betterdocs' ), | |
| 117 | + 'yaml' => __( 'YAML', 'betterdocs' ), | |
| 118 | + 'html' => __( 'HTML', 'betterdocs' ), | |
| 119 | + 'css' => __( 'CSS', 'betterdocs' ), | |
| 120 | + 'sql' => __( 'SQL', 'betterdocs' ), | |
| 121 | + 'xml' => __( 'XML', 'betterdocs' ), | |
| 122 | + 'cpp' => __( 'C++', 'betterdocs' ), | |
| 123 | + 'csharp' => __( 'C#', 'betterdocs' ), | |
| 124 | + 'go' => __( 'Go', 'betterdocs' ), | |
| 125 | + 'rust' => __( 'Rust', 'betterdocs' ), | |
| 126 | + 'swift' => __( 'Swift', 'betterdocs' ), | |
| 127 | + 'kotlin' => __( 'Kotlin', 'betterdocs' ), | |
| 128 | + 'typescript' => __( 'TypeScript', 'betterdocs' ), | |
| 129 | + ], | |
| 130 | + ] | |
| 131 | + ); | |
| 132 | + | |
| 133 | + $variant_repeater->add_control( | |
| 134 | + 'variant_code', | |
| 135 | + [ | |
| 136 | + 'label' => __( 'Code', 'betterdocs' ), | |
| 137 | + 'type' => Controls_Manager::CODE, | |
| 138 | + 'language' => 'html', | |
| 139 | + 'rows' => 10, | |
| 140 | + 'default' => '', | |
| 141 | + 'placeholder' => __( 'Paste or type your code here…', 'betterdocs' ), | |
| 142 | + ] | |
| 143 | + ); | |
| 144 | + | |
| 145 | + $this->add_control( | |
| 146 | + 'code_variants', | |
| 147 | + [ | |
| 148 | + 'label' => __( 'Additional Languages', 'betterdocs' ), | |
| 149 | + 'type' => Controls_Manager::REPEATER, | |
| 150 | + 'fields' => $variant_repeater->get_controls(), | |
| 151 | + 'default' => [], | |
| 152 | + 'title_field' => '{{{ variant_language }}}', | |
| 153 | + 'description' => __( 'Add the same snippet in other languages. A language dropdown appears when you add one or more.', 'betterdocs' ), | |
| 154 | + ] | |
| 155 | + ); | |
| 156 | + | |
| 97 | 157 | $this->end_controls_section(); |
| 98 | 158 | |
| 99 | 159 | // Display Options Section |
| 100 | 160 | $this->start_controls_section( |
| @@ -148,25 +208,8 @@ | ||
| 148 | 208 | ] |
| 149 | 209 | ); |
| 150 | 210 | |
| 151 | 211 | $this->add_control( |
| 152 | - 'show_copy_tooltip', | |
| 153 | - [ | |
| 154 | - 'label' => __( 'Enable copy tooltip', 'betterdocs' ), | |
| 155 | - 'type' => Controls_Manager::SWITCHER, | |
| 156 | - 'label_on' => __( 'Show', 'betterdocs' ), | |
| 157 | - 'label_off' => __( 'Hide', 'betterdocs' ), | |
| 158 | - 'return_value' => 'yes', | |
| 159 | - 'default' => 'no', | |
| 160 | - 'description' => __( 'Display a tooltip (‘Copied!’) on copy button hover or click.', 'betterdocs' ), | |
| 161 | - 'condition' => [ | |
| 162 | - 'show_header' => 'yes', | |
| 163 | - 'show_copy_button' => 'yes', | |
| 164 | - ], | |
| 165 | - ] | |
| 166 | - ); | |
| 167 | - | |
| 168 | - $this->add_control( | |
| 169 | 212 | 'show_line_numbers', |
| 170 | 213 | [ |
| 171 | 214 | 'label' => __( 'Show line numbers', 'betterdocs' ), |
| 172 | 215 | 'type' => Controls_Manager::SWITCHER, |
| @@ -582,14 +625,38 @@ | ||
| 582 | 625 | |
| 583 | 626 | public function view_params() { |
| 584 | 627 | $settings = $this->get_settings_for_display(); |
| 585 | 628 | |
| 629 | + // Combined [primary + additional] language list — the shared template | |
| 630 | + // renders a dropdown when it holds more than one entry. | |
| 631 | + $variants = []; | |
| 632 | + if ( ! empty( $settings['code_content'] ) ) { | |
| 633 | + $variants[] = [ | |
| 634 | + 'language' => $settings['language'], | |
| 635 | + 'code' => $settings['code_content'], | |
| 636 | + 'file_name' => isset( $settings['file_name'] ) ? $settings['file_name'] : '' | |
| 637 | + ]; | |
| 638 | + } | |
| 639 | + if ( ! empty( $settings['code_variants'] ) && is_array( $settings['code_variants'] ) ) { | |
| 640 | + foreach ( $settings['code_variants'] as $variant ) { | |
| 641 | + $code = isset( $variant['variant_code'] ) ? (string) $variant['variant_code'] : ''; | |
| 642 | + if ( '' === $code ) { | |
| 643 | + continue; | |
| 644 | + } | |
| 645 | + $variants[] = [ | |
| 646 | + 'language' => isset( $variant['variant_language'] ) ? $variant['variant_language'] : 'javascript', | |
| 647 | + 'code' => $code, | |
| 648 | + 'file_name' => '' | |
| 649 | + ]; | |
| 650 | + } | |
| 651 | + } | |
| 652 | + | |
| 586 | 653 | return [ |
| 587 | 654 | 'code_content' => $settings['code_content'], |
| 588 | 655 | 'language' => $settings['language'], |
| 656 | + 'code_variants' => $variants, | |
| 589 | 657 | 'show_language_label' => $settings['show_language_label'] === 'yes', |
| 590 | 658 | 'show_copy_button' => $settings['show_copy_button'] === 'yes', |
| 591 | - 'show_copy_tooltip' => isset( $settings['show_copy_tooltip'] ) ? $settings['show_copy_tooltip'] === 'yes' : false, | |
| 592 | 659 | 'show_header' => isset( $settings['show_header'] ) ? $settings['show_header'] === 'yes' : true, |
| 593 | 660 | 'show_line_numbers' => $settings['show_line_numbers'] === 'yes', |
| 594 | 661 | 'theme' => $settings['theme'], |
| 595 | 662 | 'widget_type' => 'elementor', |