You are here

protected function Media::prepareMedia in GridStack 8.2

Returns the formatted media as Blazy output.

1 call to Media::prepareMedia()
Media::buildMedia in src/Plugin/gridstack/stylizer/Media.php
Returns the formatted media as Blazy CSS background.

File

src/Plugin/gridstack/stylizer/Media.php, line 81

Class

Media
Provides the media styles for front-end.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

protected function prepareMedia(array $settings) {
  $build = [];
  $data = $this
    ->mediaSettings($settings);
  if (!empty($data['media_id'])) {

    // Unlike Bootstrap, Foundation wants large-12, etc., not cell-12.
    // Specific for this, Foundation is less efficient than Bootstrap.
    $build['wrapper_attributes']['class'][] = 'box__bg';
    $build['attributes']['class'][] = 'b-noratio b-gs';
    $build['attributes']['class'][] = $this
      ->getStyle('background', $settings) ? 'b-gs--bg' : 'b-gs--media';
    if ($animations = $this
      ->getAnimation($settings, 'all')) {
      foreach ($animations as $key => $value) {
        $key = str_replace('_', '-', $key);
        $key = $key == 'animation' ? $key : 'animation-' . $key;

        // @todo pos blazy 2.1:
        if ($key == 'animation') {
          $data['fx'] = $value;
        }
        else {
          $build['attributes']['data-' . $key] = $value;
        }
      }

      // @todo $build['media_attributes']['class'][] = 'box__animated';
    }

    // Overlay is only applicable to image, not video, of course.
    if ($data['media_source'] == 'image') {
      $this
        ->prepareOverlay($data, $settings);
    }

    // Image opacity.
    if (!empty($data['opacity']) && $data['opacity'] < 1) {
      $build['attributes']['style'] = 'opacity: ' . $data['opacity'] . ';';
    }

    // Disable any effect, we'll toggle by JS till required instead.
    // @todo figure out to make multiple animations work.
    // @todo if (!empty($settings['_ipe'])) {
    // @todo  $data['_fx'] = '';
    // @todo }
  }
  $build['settings'] = $data;
  return $build;
}