3 namespace Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\Updates;
5 use Drupal\bootstrap_layouts\BootstrapLayout;
6 use Drupal\bootstrap_layouts\Plugin\BootstrapLayouts\BootstrapLayoutsUpdateBase;
9 * Bootstrap Layouts Update 8401
11 * Upgrade existing Bootstrap Layout instances.
13 * @BootstrapLayoutsUpdate(
14 * id = "bootstrap_layouts_update_8401",
18 class BootstrapLayoutsUpdate8401 extends BootstrapLayoutsUpdateBase {
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()));
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])) {
33 $layout_map = $data['bootstrap_layouts_update_map'][$id];
35 // Set the new layout identifier.
36 $layout->setId($layout_map['id']);
38 // Only update the path if it's actually set.
39 $path = $layout->getPath();
41 $layout->setPath($this->getPath() . '/templates/3.0.0');
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', '');
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);
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", '');