8433a3df0a3f203401525fad1eb96af2010200b5
[yaffs-website] / BootstrapLayouts / Updates / BootstrapLayoutsUpdate8401.php
1 <?php
2
3 namespace Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\Updates;
4
5 use Drupal\bootstrap_layouts\BootstrapLayout;
6 use Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\BootstrapLayoutsUpdateBase;
7
8 /**
9  * Bootstrap Layouts Update 8401
10  *
11  * Upgrade existing Bootstrap Layout instances.
12  *
13  * @BootstrapLayoutsUpdate(
14  *   id = "bootstrap_layouts_update_8401",
15  *   schema = 8401
16  * )
17  */
18 class BootstrapLayoutsUpdate8401 extends BootstrapLayoutsUpdateBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function processExistingLayout(BootstrapLayout $layout, array $data = [], $display_messages = TRUE) {
24     // Fix any typos and replace hyphens with underscores.
25     $id = preg_replace('/\-+/', '_', preg_replace('/^booststrap/', 'bootstrap', $layout->getId()));
26
27     // Immediately return if existing layout identifier doesn't match
28     // one of the old "bootstrap_layouts" layouts.
29     if (!isset($data['bootstrap_layouts_update_map'][$id])) {
30       return;
31     }
32
33     $layout_map = $data['bootstrap_layouts_update_map'][$id];
34
35     // Set the new layout identifier.
36     $layout->setId($layout_map['id']);
37
38     // Only update the path if it's actually set.
39     $path = $layout->getPath();
40     if (isset($path)) {
41       $layout->setPath($this->getPath() . '/templates/3.0.0');
42     }
43
44     // Set default layout wrapper, attributes and classes.
45     $layout->setSetting('layout.wrapper', 'div');
46     $layout->setSetting('layout.classes', ['row', 'clearfix']);
47     $layout->setSetting('layout.attributes', '');
48
49     // Rename existing region and set region wrapper, attributes and classes.
50     foreach ($layout_map['regions'] as $old_region => $new_region) {
51       if ($old_region !== $new_region && ($region_data = $layout->getRegion($old_region))) {
52         $layout->setRegion($new_region, $region_data);
53         $layout->unsetRegion($old_region);
54       }
55       $layout->setSetting("regions.$new_region.wrapper", 'div');
56       $layout->setSetting("regions.$new_region.classes", $layout_map['classes'][$new_region]);
57       $layout->setSetting("regions.$new_region.attributes", '');
58     }
59   }
60
61 }