You are here

private function SplashifyInjection::getRenderElement in Splashify 8.2

Generated render element.

Parameters

$splash: Splash which will be displayed.

Return value

array

1 call to SplashifyInjection::getRenderElement()
SplashifyInjection::getAttach in src/Service/SplashifyInjection.php
Returns render element.

File

src/Service/SplashifyInjection.php, line 132

Class

SplashifyInjection
Class SplashifyInjection.

Namespace

Drupal\splashify\Service

Code

private function getRenderElement($splash) {
  $build = [];
  $mode = $splash
    ->getGroup()
    ->getMode();
  switch ($mode) {
    case 'redirect':
      $build = [
        '#attached' => [
          'drupalSettings' => [
            'splashify' => [
              'mode' => 'redirect',
              'url' => '/splashify/' . $splash
                ->id(),
            ],
          ],
          'library' => [
            'splashify/redirect',
          ],
        ],
      ];
      break;
    case 'window':
      $size = explode('x', $splash
        ->getGroup()
        ->getSize());
      $width = is_numeric($size[0]) ? $size[0] : 800;
      $height = is_numeric($size[1]) ? $size[1] : 600;
      $build = [
        '#attached' => [
          'drupalSettings' => [
            'splashify' => [
              'mode' => 'window',
              'url' => '/splashify/' . $splash
                ->id(),
              'size' => "width={$width}, height={$height}",
            ],
          ],
          'library' => [
            'splashify/window',
          ],
        ],
      ];
      break;
    case 'full_screen':
      $build = [
        '#theme' => 'splashify',
        '#splashify_content' => $splash
          ->getContent(),
        '#attached' => [
          'drupalSettings' => [
            'splashify' => [
              'mode' => 'full_screen',
            ],
          ],
          'library' => [
            'splashify/full_screen',
          ],
        ],
      ];
      break;
    case 'lightbox':
      $size = explode('x', $splash
        ->getGroup()
        ->getSize());
      \Drupal::service('colorbox.attachment')
        ->attach($build);
      $build['#attached']['drupalSettings']['splashify'] = [
        'mode' => 'lightbox',
        'url' => '/splashify/' . $splash
          ->id(),
        'width' => is_numeric($size[0]) ? $size[0] : 800,
        'height' => is_numeric($size[1]) ? $size[1] : 600,
      ];
      $build['#attached']['library'][] = 'splashify/lightbox';
      break;
  }
  $build['#cache']['max-age'] = 0;
  $build['#attached']['drupalSettings']['splashify']['refferer_check'] = !$splash
    ->getGroup()
    ->isDisableReferrerCheck();
  array_unshift($build['#attached']['library'], 'splashify/splash_init');
  return $build;
}