function uikit_preprocess_region

8.x-3.x preprocess.inc uikit_preprocess_region(&$variables)
8.x-2.x preprocess.inc uikit_preprocess_region(&$variables)
7.x-3.x preprocess.inc uikit_preprocess_region(&$variables)
7.x-2.x preprocess.inc uikit_preprocess_region(&$variables)

File

includes/preprocess.inc, line 84
Set up variables to be placed within the template (.html.twig) files.

Code

function uikit_preprocess_region(&$variables) {
  // Provide an id attribute to help themers.
  $region = $variables ['region'];
  $variables ['attributes']['id'] = "region--$region";

  if ($region == 'navbar') {
    $variables ['content_left'] = [];
    $variables ['content_center'] = [];
    $variables ['content_right'] = [];

    foreach ($variables ['elements'] as $id => $element) {
      if (is_array($element)) {
        $block = array();

        if (isset($element ['#id'])) {
          $block = Block::load($element ['#id']);
        }
        elseif (isset($element ['#markup'])) {
          $block = Block::load($id);
        }

        if ($block) {
          $navbar_alignment = $block->getThirdPartySetting('uikit_components', 'uikit_navbar_alignment', 'left');

          switch ($navbar_alignment) {
            case 'left':
              $variables ['content_left'][$id] = [
                '#markup' => render($element),
              ];
              break;

            case 'center':
              $variables ['content_center'][$id] = [
                '#markup' => render($element),
              ];
              break;

            case 'right':
              $variables ['content_right'][$id] = [
                '#markup' => render($element),
              ];
              break;
          }
        }
      }
    }
  }
  elseif ($region != 'offcanvas') {
    $region_style = UIkit::getThemeSetting($region . '_style');
    $card_style = UIkit::getThemeSetting($region . '_card_style');
    $region_style = $region_style ? $region_style : 0;
    $region_card_style = $card_style ? $card_style : 0;

    if ($region_style) {
      // Add the region style classes.
      switch ($region_style) {
        case 'card':
          $variables ['attributes']['class'][] = 'uk-card';
          $variables ['attributes']['class'][] = 'uk-card-body';

          if ($region_card_style) {
            $variables ['attributes']['class'][] = "uk-card-$region_card_style";
          }
          break;
      }
    }
  }
}

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Log in