--- /dev/null
+<?php
+
+namespace Cube\Elementor\Widgets;
+
+use Elementor\Controls_Manager;
+
+class TextBlock extends _Base {
+
+ // Widget name / ID
+ public function get_name() {
+ return 'cube-text';
+ }
+
+ // Elementor widget title
+ public function get_title() {
+ return __( 'Formatted Text', 'cube' );
+ }
+
+ // Elementor interface icon
+ public function get_icon() {
+ return 'eicon-post-title';
+ }
+
+ /**
+ * List of scripts the widget depends on.
+ * Used to set scripts dependencies required to run the widget.
+ *
+ * @since 1.0.0
+ * @access public
+ * @return array Widget scripts dependencies.
+ */
+ public function get_script_depends() {
+ return [];
+ }
+ /**
+ * Register the widget controls.
+ * Adds different input fields to allow the user to change and customize the widget settings.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function _register_controls() {
+
+ $this->start_controls_section(
+ 'section_content',
+ [
+ 'label' => __( 'Content', 'cube' ),
+ ]
+ );
+
+ $this->add_control(
+ 'title',
+ [
+ 'label' => __( 'Title', 'elementor' ),
+ 'type' => Controls_Manager::TEXTAREA,
+ 'placeholder' => __( 'Enter your title', 'elementor' ),
+ 'default' => '',
+ ]
+ );
+
+ $this->add_control(
+ 'title_tag',
+ [
+ 'label' => __( 'Balise de titre (SEO)', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ 'h1' => __( 'H1', 'cube' ),
+ 'h2' => __( 'H2 (Défaut)', 'cube' ),
+ 'h3' => __( 'H3', 'cube' ),
+ ],
+ 'default' => 'h2',
+ ]
+ );
+
+ $this->add_control(
+ 'body',
+ [
+ 'label' => __('Body', 'cube'),
+ 'type' => Controls_Manager::WYSIWYG,
+ 'default' => '',
+ ]
+ );
+
+ $this->add_control(
+ 'cta_text',
+ [
+ 'label' => __('Call to Action text', 'cube'),
+ 'type' => Controls_Manager::TEXT,
+ 'default' => ''
+ ]
+ );
+
+ $this->add_control(
+ 'cta_link',
+ [
+ 'label' => __('Call to Action link', 'cube'),
+ 'type' => Controls_Manager::URL,
+ 'default' => [
+ 'url' => '',
+ 'is_external' => false,
+ ],
+ 'show_external' => true
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->start_controls_section(
+ 'section_formatting',
+ [
+ 'label' => __( 'Colours & Formatting', 'cube' ),
+ ]
+ );
+
+ $this->add_control(
+ 'title_size',
+ [
+ 'label' => __( 'Title Size', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ 'text-lg' => __( 'Plus petite', 'cube' ),
+ '' => __( 'Défaut', 'cube' ),
+ 'text-2xl' => __( 'Plus grande', 'cube' ),
+ ],
+ 'default' => '',
+ ]
+ );
+
+ $this->add_control(
+ 'title_color',
+ [
+ 'label' => __( 'Title Colour', 'cube' ),
+ 'type' => Controls_Manager::COLOR,
+ 'default' => '',
+ 'selectors' => [
+ '{{WRAPPER}} .text-block-title' => 'color: {{VALUE}};',
+ ],
+ ]
+ );
+
+
+ $this->add_control(
+ 'body_color',
+ [
+ 'label' => __( 'Body Colour', 'cube' ),
+ 'type' => Controls_Manager::COLOR,
+ 'default' => '',
+ 'selectors' => [
+ '{{WRAPPER}} .text-block-body' => 'color: {{VALUE}};',
+ ],
+ ]
+ );
+
+
+ $this->add_responsive_control(
+ 'align',
+ [
+ 'label' => __( 'Alignment', 'elementor' ),
+ 'type' => Controls_Manager::CHOOSE,
+ 'options' => [
+ 'left' => [
+ 'title' => __( 'Left', 'elementor' ),
+ 'icon' => 'fa fa-align-left',
+ ],
+ 'center' => [
+ 'title' => __( 'Center', 'elementor' ),
+ 'icon' => 'fa fa-align-center',
+ ],
+ /*
+ 'right' => [
+ 'title' => __( 'Right', 'elementor' ),
+ 'icon' => 'fa fa-align-right',
+ ],
+ 'justify' => [
+ 'title' => __( 'Justified', 'elementor' ),
+ 'icon' => 'fa fa-align-justify',
+ ],
+ */
+ ],
+ 'default' => 'left',
+ 'prefix_class' => 'text-block-align-',
+ ]
+ );
+
+ $this->add_control(
+ 'max_width',
+ [
+ 'label' => __( 'Maximum Width', 'cube' ),
+ 'type' => Controls_Manager::SLIDER,
+ // 'default' => [
+ // 'size' => 400,
+ // ],
+ 'range' => [
+ 'px' => [
+ 'min' => 400,
+ 'max' => 1600,
+ 'step' => 10,
+ ],
+ '%' => [
+ 'min' => 0,
+ 'max' => 100,
+ ],
+ ],
+ 'selectors' => [
+ '{{WRAPPER}} .text-block' => 'max-width: {{SIZE}}{{UNIT}};',
+ ],
+ ]
+ );
+
+ $this->add_control(
+ 'block_position',
+ [
+ 'label' => __('Positionnement de bloc', 'cube'),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => [
+ '' => __( 'Défaut', 'cube' ),
+ 'margin-left: auto; margin-right: auto;' => __( 'Centré', 'cube' ),
+ 'margin-right: auto;' => __( 'Gauche', 'cube' ),
+ 'margin-left: auto;' => __( 'Droite', 'cube' ),
+ ],
+ 'default' => '',
+ 'selectors' => [
+ '{{WRAPPER}} .text-block' => '{{VALUE}}',
+ ],
+ ]
+ );
+
+ $this->end_controls_section();
+
+ $this->common_controls();
+ }
+ /**
+ * Render the widget output on the frontend.
+ * Written in PHP and used to generate the final HTML.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function render() {
+
+ $title = $this->get_settings('title');
+ $title_tag = $this->get_settings('title_tag');
+ $title_size = $this->get_settings('title_size');
+ $body = $this->parse_text_editor($this->get_settings('body'));
+ $cta_text = $this->get_settings('cta_text');
+ $cta_link = $this->get_settings('cta_link');
+
+ if (empty($title_size)) {
+ $title_size = 'text-xl';
+ }
+
+ if ( ! empty( $cta_link['url'] ) ) {
+ $this->add_render_attribute( 'cta_text', 'href', $cta_link['url'] );
+
+ if ( $cta_link['is_external'] ) {
+ $this->add_render_attribute( 'cta_text', 'target', '_blank' );
+ }
+
+ if ( $cta_link['nofollow'] ) {
+ $this->add_render_attribute( 'cta_text', 'rel', 'nofollow' );
+ }
+ }
+
+ // Inline Editing settings
+ $this->add_inline_editing_attributes('title', 'none');
+ $this->add_inline_editing_attributes('body', 'advanced');
+ $this->add_inline_editing_attributes('cta_text', 'none');
+
+ // CSS Classes for elements
+ $this->add_render_attribute('title', 'class', ["text-block-title $title_size"]);
+ $this->add_render_attribute('body', 'class', ['text-block-body']);
+ $this->add_render_attribute('cta_text', 'class', ['text-block-cta btn']);
+
+ // Rendered content
+ echo '<div class="text-block">';
+ if (!empty($title)) echo "<{$title_tag} {$this->get_render_attribute_string('title')}>$title</{$title_tag}>";
+ if (!empty($body)) echo "<div {$this->get_render_attribute_string('body')}>$body</div>";
+ if (!empty($cta_text)) {
+ echo '<a '. $this->get_render_attribute_string('cta_text') .'>';
+ echo $cta_text;
+ echo '</a>';
+ }
+ echo '</div>';
+ }
+
+ /**
+ * Render text editor widget output in the editor.
+ *
+ * Written as a Backbone JavaScript template and used to generate the live preview.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function _content_template() {
+ ?>
+ <#
+
+ var title_size = (settings.title_size == '') ? 'text-xl' : settings.title_size;
+
+ view.addRenderAttribute( 'title', 'class', ['text-block-title '+ title_size]);
+ view.addRenderAttribute( 'body', 'class', ['text-block-body']);
+ view.addRenderAttribute( 'cta_text', 'class', ['text-block-cta btn']);
+
+ view.addInlineEditingAttributes( 'title', 'none' );
+ view.addInlineEditingAttributes( 'body', 'advanced' );
+ view.addInlineEditingAttributes( 'cta_text', 'none' );
+ #>
+ <div class="text-block">
+
+ <# if ('' !== settings.title) { #>
+ <{{{ settings.title_tag }}} {{{ view.getRenderAttributeString( 'title' ) }}}>{{{ settings.title }}}</{{{ settings.title_tag }}}>
+ <# } #>
+
+ <# if ('' !== settings.body) { #>
+ <div {{{ view.getRenderAttributeString( 'body' ) }}}>{{{ settings.body }}}</div>
+ <# } #>
+
+ <# if ('' !== settings.cta_text) { #>
+ <a {{{ view.getRenderAttributeString( 'cta_text' ) }}}>
+ {{{ settings.cta_text }}}
+ </a>
+ <# } #>
+
+ </div>
+ <?php
+ }
+
+}