You are here

public function Media::buildMedia in GridStack 8.2

Returns the formatted media as Blazy CSS background.

File

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

Class

Media
Provides the media styles for front-end.

Namespace

Drupal\gridstack\Plugin\gridstack\stylizer

Code

public function buildMedia(array &$attributes, array &$settings) {
  $data = $this
    ->prepareMedia($settings);
  $config = $data['settings'];
  if (isset($config['media_id']) && ($mid = $config['media_id'])) {
    $media = MediaEntity::load($mid);

    // @todo remove post blazy:2.1+.
    if (isset($config['responsive_image_style']) && ($resimage = $config['responsive_image_style'])) {
      $data['settings']['resimage'] = $this->blazyEntity
        ->blazyManager()
        ->entityLoad($resimage, 'responsive_image_style');
    }

    // Pass results to \Drupal\blazy\BlazyEntity.
    $settings['has_media'] = TRUE;
    $attributes['class'][] = 'is-gs-media';
    return $this->blazyEntity
      ->build($data, $media, $media
      ->label());
  }
  return [];
}