You are here

bootstrap_layout_builder.module in Bootstrap Layout Builder 1.x

Same filename and directory in other branches
  1. 2.x bootstrap_layout_builder.module

Bootstrap Layout Builder module.

File

bootstrap_layout_builder.module
View source
<?php

/**
 * @file
 * Bootstrap Layout Builder module.
 */
use Drupal\Core\Render\Element;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function bootstrap_layout_builder_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the bootstrap_layout_builder module.
    case 'help.page.bootstrap_layout_builder':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Add Bootstrap Grid support to Layout Builder module.
      currently, work for both Bootstrap 3 and Bootstrap 4.') . '</p>';
      return $output;
    default:
  }
}

/**
 * Implements hook_theme().
 */
function bootstrap_layout_builder_theme() {
  return [
    'row_columns' => [
      'template' => 'row-columns',
      'render element' => 'content',
    ],
  ];
}

/**
 * Implements hook_preprocess_HOOK().
 */
function bootstrap_layout_builder_preprocess_row_columns(&$variables) {

  // Create an attributes variable for each region.
  $direct_attributes_mapping = [
    'container_wrapper',
    'container',
  ];
  $variables['video_background_url'] = NULL;
  foreach (Element::children($variables['content']) as $name) {
    if (in_array($name, $direct_attributes_mapping)) {
      if (isset($variables['content'][$name]['#attributes'])) {
        $variables[$name . '_attributes'] = new Attribute($variables['content'][$name]['#attributes']);
      }

      // video_background_url var.
      if ($name == 'container_wrapper') {
        if (isset($variables['content']['container_wrapper']['#video_background_url'])) {
          $variables['video_background_url'] = $variables['content']['container_wrapper']['#video_background_url'];
        }
        if (isset($variables['content']['container_wrapper']['#video_wrapper_classes'])) {
          $variables['video_wrapper_classes'] = $variables['content']['container_wrapper']['#video_wrapper_classes'];
        }
      }
    }
    if (!isset($variables['content'][$name]['#attributes'])) {
      $variables['content'][$name]['#attributes'] = [];
    }
    $variables['region_attributes'][$name] = new Attribute($variables['content'][$name]['#attributes']);
  }
}