From a72c47228c72f9a6b85d3e2c8cf97b00fed19fc3 Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Wed, 23 Dec 2020 23:45:31 +0100 Subject: [PATCH] WIP #4064 @8 --- .../mu-plugins/cube/src/Elementor/Setup.php | 14 ++ .../src/Elementor/Widgets/IntroCarousel.php | 176 ++++++++++++++++++ .../views/widgets/intro-carousel.blade.php | 27 +++ 3 files changed, 217 insertions(+) create mode 100644 web/app/mu-plugins/cube/src/Elementor/Widgets/IntroCarousel.php create mode 100644 web/app/themes/Usines/resources/views/widgets/intro-carousel.blade.php diff --git a/web/app/mu-plugins/cube/src/Elementor/Setup.php b/web/app/mu-plugins/cube/src/Elementor/Setup.php index e820b45..13f6c0a 100644 --- a/web/app/mu-plugins/cube/src/Elementor/Setup.php +++ b/web/app/mu-plugins/cube/src/Elementor/Setup.php @@ -26,6 +26,7 @@ class Setup { $elementor = Plugin::$instance; $elementor->widgets_manager->register_widget_type( new Widgets\TextBlock() ); + $elementor->widgets_manager->register_widget_type( new Widgets\IntroCarousel() ); } @@ -96,6 +97,19 @@ class Setup { // Layered Backgrounds - PHP (Frontend) add_action('elementor/frontend/section/before_render', function (Element_Base $element) { + $children = $element->get_children(); + $cols = count($children); + + $element->add_render_attribute('_wrapper', 'data-cols', $cols); + +// echo "

COLS: $cols

"; +// echo "
";
+//            /* @var \Elementor\Element_Column $el */
+//            foreach ($children as $child) {
+//                print_r($child->get_data()['settings']);
+//            }
+//            echo "
"; + $settings = $element->get_settings(); // Since the normal Elementor section is wrapped by this code, we need to apply the element ID diff --git a/web/app/mu-plugins/cube/src/Elementor/Widgets/IntroCarousel.php b/web/app/mu-plugins/cube/src/Elementor/Widgets/IntroCarousel.php new file mode 100644 index 0000000..dd378c1 --- /dev/null +++ b/web/app/mu-plugins/cube/src/Elementor/Widgets/IntroCarousel.php @@ -0,0 +1,176 @@ +start_controls_section( + 'section_content', + [ + 'label' => __( 'Intro Carousel', 'cube' ), + ] + ); + + $this->add_control( + 'title', + [ + 'label' => __( 'Title', 'elementor' ), + 'type' => Controls_Manager::TEXTAREA, + 'placeholder' => __( 'Enter your title', 'elementor' ), + 'default' => '', + ] + ); + + $this->add_control( + 'body', + [ + 'label' => __('Body', 'cube'), + 'type' => Controls_Manager::TEXTAREA, + 'default' => '', + ] + ); + + $this->add_control( + 'cta_text', + [ + 'label' => __('Button text', 'cube'), + 'type' => Controls_Manager::TEXT, + 'default' => '' + ] + ); + + $this->add_control( + 'cta_link', + [ + 'label' => __('Button link', 'cube'), + 'type' => Controls_Manager::URL, + 'default' => [ + 'url' => '', + 'is_external' => false, + ], + 'show_external' => true + ] + ); + + $repeater = new Repeater(); + + $repeater->add_control( + 'image', + [ + 'label' => __('Photo', 'cube'), + 'type' => Controls_Manager::MEDIA, + 'default' => [ + 'url' => Utils::get_placeholder_image_src(), + ], + ] + ); + + $repeater->add_control( + 'background_image', + [ + 'label' => __('Background', 'cube'), + 'type' => Controls_Manager::MEDIA, + 'default' => [ + 'url' => Utils::get_placeholder_image_src(), + ], + ] + ); + + $repeater->add_control( + 'caption', + [ + 'label' => __('Caption', 'cube'), + 'title_block' => true, + 'type' => Controls_Manager::TEXT, + 'default' => '' + ] + ); + + $this->add_control( + 'slides', + [ + 'label' => __('Slides', 'cube'), + 'type' => Controls_Manager::REPEATER, + 'prevent_empty' => false, + 'fields' => $repeater->get_controls(), + 'title_field' => '
{{{ caption }}}', + ] + ); + + + + $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() { + + $id = 'intro_carousel_' . $this->get_id(); + $title = $this->get_settings('title'); + $body = $this->get_settings('body'); + $cta_text = $this->get_settings('cta_text'); + $cta_link = $this->get_settings('cta_link'); + $slides = $this->get_settings('slides'); + + echo view('widgets/intro-carousel', compact('id', 'title', 'body', 'cta_text', 'cta_link', 'slides')); + } +} diff --git a/web/app/themes/Usines/resources/views/widgets/intro-carousel.blade.php b/web/app/themes/Usines/resources/views/widgets/intro-carousel.blade.php new file mode 100644 index 0000000..657355e --- /dev/null +++ b/web/app/themes/Usines/resources/views/widgets/intro-carousel.blade.php @@ -0,0 +1,27 @@ +{{-- INTRO CAROUSEL --}} + -- 2.39.5