← All changes
|
modules/atomic-widgets/elements/base/has-template.php
+22
-3
4.0.9
→
4.3.0-beta3
View file →
| @@ -13,8 +13,12 @@ | ||
| 13 | 13 | * @mixin Has_Atomic_Base |
| 14 | 14 | */ |
| 15 | 15 | trait Has_Template { |
| 16 | 16 | |
| 17 | + private static function get_macros_template_key(): string { | |
| 18 | + return 'elementor/macros'; | |
| 19 | + } | |
| 20 | + | |
| 17 | 21 | public function get_initial_config() { |
| 18 | 22 | $config = parent::get_initial_config(); |
| 19 | 23 | |
| 20 | 24 | $config['twig_main_template'] = $this->get_main_template(); |
| @@ -21,13 +25,25 @@ | ||
| 21 | 25 | $config['twig_templates'] = $this->get_templates_contents(); |
| 22 | 26 | return $config; |
| 23 | 27 | } |
| 24 | 28 | |
| 29 | + protected function transform_link_for_render( array $parsed ): array { | |
| 30 | + return $parsed; | |
| 31 | + } | |
| 32 | + | |
| 33 | + protected function get_shared_templates(): array { | |
| 34 | + return [ | |
| 35 | + self::get_macros_template_key() => __DIR__ . '/_macros.html.twig', | |
| 36 | + ]; | |
| 37 | + } | |
| 38 | + | |
| 25 | 39 | protected function render() { |
| 26 | 40 | try { |
| 27 | 41 | $renderer = Template_Renderer::instance(); |
| 28 | 42 | |
| 29 | - foreach ( $this->get_templates() as $name => $path ) { | |
| 43 | + $all_templates = array_merge( $this->get_shared_templates(), $this->get_templates() ); | |
| 44 | + | |
| 45 | + foreach ( $all_templates as $name => $path ) { | |
| 30 | 46 | if ( $renderer->is_registered( $name ) ) { |
| 31 | 47 | continue; |
| 32 | 48 | } |
| 33 | 49 | |
| @@ -33,13 +49,16 @@ | ||
| 33 | 49 | |
| 34 | 50 | $renderer->register( $name, $path ); |
| 35 | 51 | } |
| 36 | 52 | |
| 53 | + $settings = $this->get_atomic_settings(); | |
| 54 | + | |
| 37 | 55 | $context = [ |
| 38 | 56 | 'id' => $this->get_id(), |
| 39 | 57 | 'interaction_id' => $this->get_interaction_id(), |
| 40 | 58 | 'type' => $this->get_name(), |
| 41 | - 'settings' => $this->get_atomic_settings(), | |
| 59 | + 'settings' => $settings, | |
| 60 | + 'tag' => static::get_computed_html_tag( $settings ), | |
| 42 | 61 | 'base_styles' => $this->get_base_styles_dictionary(), |
| 43 | 62 | ]; |
| 44 | 63 | |
| 45 | 64 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| @@ -53,9 +72,9 @@ | ||
| 53 | 72 | |
| 54 | 73 | protected function get_templates_contents() { |
| 55 | 74 | return array_map( |
| 56 | 75 | fn ( $path ) => Utils::file_get_contents( $path ), |
| 57 | - $this->get_templates() | |
| 76 | + array_merge( $this->get_shared_templates(), $this->get_templates() ) | |
| 58 | 77 | ); |
| 59 | 78 | } |
| 60 | 79 | |
| 61 | 80 | protected function get_main_template() { |