-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.helpers.php
More file actions
89 lines (67 loc) · 2.42 KB
/
Copy pathclass.helpers.php
File metadata and controls
89 lines (67 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace CNP;
class Helpers {
/**
* set_background_on_structure_array.
*
* Set a background, no matter what kind of organism you're dealing with! Interchangeable between slides, headers, blurbs, whatever!
*
* TODO: standardize "background_type" field options across all layouts.
*
* @param $data
* @param $background_key
* @param $structure_array
*
* @return mixed
*/
public static function set_background_on_structure_array( $data, $background_key, $structure_array, $args = array() ) {
$background_type = $data['background_type'];
// @EXIT: If there is no background, get rid of the atom.
if ( 'None' === $background_type ) {
unset( $structure_array[ $background_key ] );
return $structure_array;
}
if ( 'Image' === $background_type ) {
// @EXIT: If there's no image set, get rid of the atom.
if ( empty( $data['background_image'] ) ) {
unset( $structure_array[ $background_key ] );
return $structure_array;
}
// Items are handled one-by-one so we don't accidentally overwrite preset array values.
$structure_array[ $background_key ]['parts']['image'] = [
'atom' => 'Image',
'attachment_id' => $data['background_image'],
'size' => isset( $args['image-size'] ) ? $args['image-size'] : 'full',
'attributes' => [
'sizes' => '100vw',
],
];
}
if ( 'Video' === $background_type ) {
// If there's no video or image files, get rid of the atom.
if ( empty( $data['mp4'] ) && empty( $data['webm'] ) && empty( $data['jpg'] ) ) {
unset( $structure_array[ $background_key ] );
return $structure_array;
}
$structure_array[ $background_key ]['atom'] = 'BackgroundVideo';
if ( ! empty( $data['mp4'] ) ) {
$structure_array[ $background_key ]['mp4'] = 'mp4:' . $data['mp4']['url'];
}
if ( ! empty( $data['webm'] ) ) {
$structure_array[ $background_key ]['webm'] = 'webm:' . $data['webm']['url'];
}
if ( ! empty( $data['jpg'] ) ) {
$structure_array[ $background_key ]['jpg'] = 'poster:' . $data['jpg']['url'];
}
}
if ( 'Color' === $background_type ) {
// If there's no color set, get rid of the atom.
if ( empty( $data['background_color'] ) ) {
unset( $structure_array[ $background_key ] );
return $structure_array;
}
$structure_array[ $background_key ]['attributes']['style'] = 'background-color: ' . $data['background_color'] . ';';
}
return $structure_array;
}
}