PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.2
Elementor Website Builder – more than just a page builder v4.3.2
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
← All changes | modules/mcp/abilities/manage-component-ability.php +40 -0 4.3.0-beta2 → 4.3.2 View file →
@@ -14,8 +14,9 @@
14 14 use Elementor\Modules\Mcp\Abilities\Utils\Composition_Compiler;
15 15 use Elementor\Modules\Mcp\Abilities\Utils\Insufficient_Permissions_Error;
16 16 use Elementor\Modules\Mcp\Abilities\Utils\Overridable_Props_Builder;
17 17 use Elementor\Modules\Mcp\Abilities\Utils\Prompt_Loader;
18 +use Elementor\Modules\Mcp\Events\Mcp_Event_Dispatcher;
18 19 use Elementor\Plugin;
19 20
20 21 if ( ! defined( 'ABSPATH' ) ) {
21 22 exit;
@@ -137,8 +138,10 @@
137 138 }
138 139
139 140 $component = $this->get_repository()->get( $component_id, false );
140 141
142 + $this->emit_component_created_event( $title, $component_id, $elements );
143 +
141 144 $response = [
142 145 'success' => true,
143 146 'component_id' => $component_id,
144 147 'uid' => $uid,
@@ -732,7 +735,44 @@
732 735 'items' => [ 'type' => 'integer' ],
733 736 'description' => 'archive targets.',
734 737 ],
735 738 ],
739 + ];
740 + }
741 +
742 + private function emit_component_created_event( string $title, int $component_id, array $elements ): void {
743 + [ 'elements_count' => $nested_elements_count, 'components_count' => $nested_components_count ] = $this->count_nested_elements( $elements );
744 + $top_element_type = $elements[0]['elType'] ?? ( $elements[0]['widgetType'] ?? '' );
745 +
746 + Mcp_Event_Dispatcher::emit( 'component_created', [
747 + 'id' => (string) $component_id,
748 + 'name' => $title,
749 + 'nested_elements_count' => $nested_elements_count,
750 + 'nested_components_count' => $nested_components_count,
751 + 'top_element_type' => $top_element_type,
752 + ] );
753 + }
754 +
755 + private function count_nested_elements( array $elements ): array {
756 + $elements_count = count( $elements );
757 + $components_count = 0;
758 +
759 + foreach ( $elements as $element ) {
760 + if ( 'e-component' === ( $element['widgetType'] ?? '' ) ) {
761 + $components_count++;
762 + }
763 +
764 + $children = $element['elements'] ?? [];
765 +
766 + if ( ! empty( $children ) ) {
767 + $child_counts = $this->count_nested_elements( $children );
768 + $elements_count += $child_counts['elements_count'];
769 + $components_count += $child_counts['components_count'];
770 + }
771 + }
772 +
773 + return [
774 + 'elements_count' => $elements_count,
775 + 'components_count' => $components_count,
736 776 ];
737 777 }
738 778 }