PluginProbe
YayMail – WooCommerce Email Customizer / 4.4.2
YayMail – WooCommerce Email Customizer v4.4.2
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Builder / ElementBuilder.php

ElementBuilder.php in YayMail – WooCommerce Email Customizer 4.4.2, at src/Builder/ElementBuilder.php

70 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace YayMail\Builder;
3
4 /**
5 * Builder class for constructing email elements
6 */
7 class ElementBuilder {
8 /**
9 * Array of elements to build
10 *
11 * @var array
12 */
13 protected $elements = [];
14
15 /**
16 * Constructor
17 */
18 public function __construct() {}
19
20 public function add_element( $type, $attributes ) {
21 $this->elements[] = [
22 'type' => $type,
23 'attributes' => $attributes,
24 ];
25
26 return $this;
27 }
28
29 public function build() {
30 $built_elements = [];
31
32 foreach ( $this->elements as $element ) {
33 $element_type = $element['type'];
34 $attributes = $element['attributes'];
35
36 if ( isset( $element['integration'] ) && '3rd' === $element['integration'] ) {
37 $class = 'YayMail\Integrations\\' . $element_type;
38 } elseif ( ! empty( $element['addon_namespace'] ) ) {
39 $class = $element['addon_namespace'] . '\\Elements\\' . $element_type;
40 } else {
41 $class = 'YayMail\Elements\\' . $element_type;
42 }
43
44 if ( ! class_exists( $class ) ) {
45 continue;
46 }
47
48 if ( 'ColumnLayout' === $element_type ) {
49 $amount_of_columns = $attributes['amount_of_columns'] ?? 1;
50 unset( $attributes['amount_of_columns'] );
51 $element_data = $class::get_data( $amount_of_columns, $attributes );
52 } elseif ( 'Column' === $element_type ) {
53 $width = $attributes['column_width'] ?? 5;
54 unset( $attributes['column_width'] );
55 $element_data = $class::get_data( $width, $attributes );
56 } else {
57 $element_data = $class::get_data( $attributes );
58 }
59
60 if ( isset( $attributes['children'] ) && is_array( $attributes['children'] ) ) {
61 $element_data['children'] = array_merge( ...array_values( $attributes['children'] ) );
62 }
63
64 $built_elements[] = $element_data;
65 }//end foreach
66
67 return $built_elements;
68 }
69 }
70