FlexibleLayout.php

Public

Get raw version
php
  1. <?php
  2.  
  3. /**
  4.  * @file
  5.  * Contains \Drupal\my_layouts\Plugin\Layout\FlexibleLayout.
  6.  */
  7.  
  8. namespace Drupal\my_layouts\Plugin\Layout;
  9.  
  10. use Drupal\layout_plugin\Plugin\Layout\LayoutBase;
  11.  
  12. /**
  13.  * A layout from our flexible layout builder.
  14.  *
  15.  * @ingroup layout_template_plugins
  16.  *
  17.  * @Layout(
  18.  * id = "flexible_layout",
  19.  * deriver = "Drupal\my_layouts\Plugin\Deriver\FlexibleLayoutDeriver"
  20.  * )
  21.  */
  22. class FlexibleLayout extends LayoutBase {
  23.  
  24. /**
  25.   * {@inheritdoc}
  26.   */
  27. public function build(array $regions) {
  28. // Add Susy classes to markup.
  29. foreach ($regions as $region_name => $region_data) {
  30. $matches = [];
  31. if (preg_match('/.*?_col_(.*)/', $region_name, $matches)) {
  32. if ($matches[1]) {
  33. $regions[$region_name]['#prefix'] = sprintf('<div class="col__%s">', $matches[1]) . $regions[$region_name]['#prefix'];
  34. $regions[$region_name]['#suffix'] .= '</div>';
  35. }
  36. }
  37. }
  38. $render_array = parent::build($regions);
  39.  
  40. return $render_array;
  41. }
  42.  
  43. }