annotate themes/contrib/mayo/inc/forms/mayo.submit.responsive.inc @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents 5311817fb629
children
rev   line source
Chris@2 1 <?php
Chris@2 2 use Drupal\Component\Utility\Html;
Chris@2 3 /**
Chris@2 4 * @file
Chris@2 5 * Build and save the responsive layout.
Chris@2 6 *
Chris@2 7 * This is the main submit handler for building the layout.
Chris@2 8 * The output is a stylesheet saved to public
Chris@2 9 * files - the main responsive layout.
Chris@2 10 */
Chris@2 11 function mayo_submit_responsive($values, $theme_name, $path) {
Chris@2 12 global $_path_to_mayo;
Chris@2 13
Chris@2 14 // Set up some paths we use to get and save files
Chris@2 15 $path_to_responsive_css = drupal_get_path('theme', $theme_name) . '/css/';
Chris@2 16 $path_to_panels_css = $_path_to_mayo . '/layouts/css/';
Chris@2 17
Chris@2 18 // Get the page layout config array
Chris@2 19 $layout_variables = assemble_page_layout();
Chris@2 20
Chris@2 21 // $layouts will hold all the page level layouts
Chris@2 22 $layouts = array();
Chris@2 23
Chris@2 24 // Initialize the $is_default_layout variable, we use this to test against
Chris@2 25 $is_default_layout = 'smalltouch-portrait';
Chris@2 26
Chris@2 27 // Holds all styles from the responsive stylesheets
Chris@2 28 $responsive_styles = array();
Chris@2 29
Chris@2 30 // Smalltouch Landscape
Chris@2 31 if ($values['smalltouch_landscape_layout']) {
Chris@2 32
Chris@2 33 $device = 'smalltouch_landscape';
Chris@2 34
Chris@2 35 // Build an array of page layout settings values
Chris@2 36 foreach ($layout_variables as $key => $value) {
Chris@2 37 if (isset($values["$device" . '_' . "$value"])) {
Chris@2 38 $smalltouch_landscape_layout_data[$value] = Html::escape($values["$device" . '_' . "$value"]);
Chris@2 39 }
Chris@2 40 }
Chris@2 41 $layout = mayo_build_page_layout($smalltouch_landscape_layout_data['layout'], $smalltouch_landscape_layout_data['sidebar_first'], $smalltouch_landscape_layout_data['sidebar_second'], $smalltouch_landscape_layout_data['sidebar_unit'], $theme_name);
Chris@2 42
Chris@2 43 $method = $smalltouch_landscape_layout_data['layout'];
Chris@2 44 $comment = "/* $device $method */\n";
Chris@2 45 $width = "\n" . '#page-wrapper {width:' . $smalltouch_landscape_layout_data['page_width'] . $smalltouch_landscape_layout_data['page_unit'] . '}';
Chris@2 46 $media_query = $smalltouch_landscape_layout_data['media_query'];
Chris@2 47
Chris@2 48 // Build the styles string
Chris@2 49 $styles = $width . "\n" . $layout;
Chris@2 50
Chris@2 51 // CSS wrapped in the media query
Chris@2 52 $css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
Chris@2 53
Chris@2 54 // Get and wrap the responsive CSS styles in the relative media query
Chris@2 55 $responsive_smalltouch_landscape_css = '';
Chris@2 56 $layouts[] = $css;
Chris@2 57 }
Chris@2 58
Chris@2 59 // Tablet Portrait
Chris@2 60 if ($values['tablet_portrait_layout']) {
Chris@2 61
Chris@2 62 $device = 'tablet_portrait';
Chris@2 63
Chris@2 64 // Build an array of page layout settings values
Chris@2 65 foreach ($layout_variables as $key => $value) {
Chris@2 66 if (isset($values["$device" . '_' . "$value"])) {
Chris@2 67 $tablet_portrait_layout_data[$value] = Html::escape($values["$device" . '_' . "$value"]);
Chris@2 68 }
Chris@2 69 }
Chris@2 70 // Workaround upgrade issues for some settings
Chris@2 71 if ($tablet_portrait_layout_data['layout'] == 'two_col_stack') {
Chris@2 72 $tablet_portrait_layout_data['layout'] = 'two_sidebars_right_stack';
Chris@2 73 }
Chris@2 74 $layout = mayo_build_page_layout($tablet_portrait_layout_data['layout'], $tablet_portrait_layout_data['sidebar_first'], $tablet_portrait_layout_data['sidebar_second'], $tablet_portrait_layout_data['sidebar_unit'], $theme_name);
Chris@2 75
Chris@2 76 $method = $tablet_portrait_layout_data['layout'];
Chris@2 77 $comment = "/* $device $method */\n";
Chris@2 78 $width = "\n" . '#page-wrapper {width:' . $tablet_portrait_layout_data['page_width'] . $tablet_portrait_layout_data['page_unit'] . '}';
Chris@2 79 $media_query = $tablet_portrait_layout_data['media_query'];
Chris@2 80
Chris@2 81 // Build the styles string
Chris@2 82 $styles = $width . "\n" . $layout;
Chris@2 83
Chris@2 84 // CSS wrapped in the media query
Chris@2 85 $css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
Chris@2 86 $layouts[] = $css;
Chris@2 87 }
Chris@2 88
Chris@2 89 // Tablet Landscape
Chris@2 90 if ($values['tablet_landscape_layout']) {
Chris@2 91
Chris@2 92 $device = 'tablet_landscape';
Chris@2 93
Chris@2 94 // Build an array of page layout settings values
Chris@2 95 foreach ($layout_variables as $key => $value) {
Chris@2 96 if (isset($values["$device" . '_' . "$value"])) {
Chris@2 97 $tablet_landscape_layout_data[$value] = Html::escape($values["$device" . '_' . "$value"]);
Chris@2 98 }
Chris@2 99 }
Chris@2 100 // Workaround upgrade issues for some settings
Chris@2 101 if ($tablet_portrait_layout_data['layout'] == 'two_col_stack') {
Chris@2 102 $tablet_portrait_layout_data['layout'] = 'two_sidebars_right_stack';
Chris@2 103 }
Chris@2 104 $layout = mayo_build_page_layout($tablet_landscape_layout_data['layout'], $tablet_landscape_layout_data['sidebar_first'], $tablet_landscape_layout_data['sidebar_second'], $tablet_landscape_layout_data['sidebar_unit'], $theme_name);
Chris@2 105
Chris@2 106 $method = $tablet_landscape_layout_data['layout'];
Chris@2 107 $comment = "/* $device $method */\n";
Chris@2 108 $width = "\n" . '#page-wrapper {width:' . $tablet_landscape_layout_data['page_width'] . $tablet_landscape_layout_data['page_unit'] . '}';
Chris@2 109 $media_query = $tablet_landscape_layout_data['media_query'];
Chris@2 110
Chris@2 111 // Build the styles string
Chris@2 112 $styles = $width . "\n" . $layout;
Chris@2 113
Chris@2 114 // CSS wrapped in the media query
Chris@2 115 $css = $comment . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
Chris@2 116 $layouts[] = $css;
Chris@2 117 }
Chris@2 118 // Standard Layout (bigscreen)
Chris@2 119 if ($values['bigscreen_layout']) {
Chris@2 120
Chris@2 121 $device = 'bigscreen';
Chris@2 122 // Build an array of page layout settings values
Chris@2 123 foreach ($layout_variables as $key => $value) {
Chris@2 124 if (isset($values["$device" . '_' . "$value"])) {
Chris@2 125 $bigscreen_layout_data[$value] = Html::escape($values["$device" . '_' . "$value"]);
Chris@2 126 }
Chris@2 127 }
Chris@2 128 $layout = mayo_build_page_layout($bigscreen_layout_data['layout'], $bigscreen_layout_data['sidebar_first'], $bigscreen_layout_data['sidebar_second'], $bigscreen_layout_data['sidebar_unit'], $theme_name);
Chris@2 129
Chris@2 130 $method = $bigscreen_layout_data['layout'];
Chris@2 131 $comment = "/* $device $method */";
Chris@2 132 $width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . '}';
Chris@2 133 $media_query = $bigscreen_layout_data['media_query'];
Chris@2 134
Chris@2 135 // Standard layout can have a max-width
Chris@2 136 $values['bigscreen_set_max_width'] = 0;
Chris@2 137 if ($values['bigscreen_set_max_width'] === 1 && $bigscreen_layout_data['page_unit'] === '%') {
Chris@2 138 if (!empty($values['bigscreen_max_width'])) {
Chris@2 139 $width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . ';max-width:' . $values['bigscreen_max_width'] . $values['bigscreen_max_width_unit'] . '}';
Chris@2 140 }
Chris@2 141 else {
Chris@2 142 $width = "\n" . '#page-wrapper {width:' . $bigscreen_layout_data['page_width'] . $bigscreen_layout_data['page_unit'] . ';max-width:' . $values['bigscreen_max_width'] . $values['bigscreen_max_width_unit'] . '}';
Chris@2 143 }
Chris@2 144 }
Chris@2 145
Chris@2 146 // Build the styles string
Chris@2 147 $styles = $width . "\n" . $layout;
Chris@2 148 $css = $comment . "\n" . '@media ' . $media_query . ' {' . $styles . "\n" . '}';
Chris@2 149
Chris@2 150 // add $css to the layouts array
Chris@2 151 $layouts[] = $css;
Chris@2 152 }
Chris@2 153 //****** END bigscreen layout ******//
Chris@2 154
Chris@2 155 // Get and wrap the responsive CSS styles in the relative media query
Chris@2 156 // responsive layout
Chris@2 157 $responsive_layout_data = implode("\n", $layouts);
Chris@2 158 $responsive_layout = $responsive_layout_data;
Chris@2 159
Chris@2 160 // Build a keyed array: file names as key, layout data as value
Chris@2 161 $files = array(
Chris@2 162 "$theme_name.responsive.layout" => $responsive_layout,
Chris@2 163 );
Chris@2 164
Chris@2 165 // Loop over the array and save each file, and we're done!
Chris@2 166 foreach ($files as $key => $value) {
Chris@2 167 $filepath = "$path/$key.css";
Chris@2 168 file_unmanaged_save_data($value, $filepath, FILE_EXISTS_REPLACE);
Chris@2 169 }
Chris@2 170 }