├── src ├── LightboxAsset.php └── Lightbox.php ├── composer.json └── README.md /src/LightboxAsset.php: -------------------------------------------------------------------------------- 1 | [ 33 | [ 34 | 'thumb' => 'url/to/thumb.ext', 35 | 'original' => 'url/to/original.ext', 36 | 'title' => 'optional title', 37 | ], 38 | ] 39 | ]); 40 | ``` 41 | -------------------------------------------------------------------------------- /src/Lightbox.php: -------------------------------------------------------------------------------- 1 | getView()); 17 | } 18 | 19 | /** @inheritdoc */ 20 | public function run() { 21 | $html = ''; 22 | foreach ($this->files as $file) { 23 | if (!isset($file['thumb']) || !isset($file['original'])) { 24 | continue; 25 | } 26 | 27 | $attributes = [ 28 | 'data-title' => isset($file['title']) ? $file['title'] : '', 29 | ]; 30 | 31 | if (isset($file['group'])) { 32 | $attributes['data-lightbox'] = $file['group']; 33 | } else { 34 | $attributes['data-lightbox'] = 'image-' . uniqid(); 35 | } 36 | 37 | $thumbOptions = isset($file['thumbOptions']) ? $file['thumbOptions'] : []; 38 | $linkOptions = isset($file['linkOptions']) ? $file['linkOptions'] : []; 39 | 40 | $img = Html::img($file['thumb'], $thumbOptions); 41 | $a = Html::a($img, $file['original'], ArrayHelper::merge($attributes, $linkOptions)); 42 | 43 | $html .= $a; 44 | } 45 | return $html; 46 | } 47 | 48 | } 49 | --------------------------------------------------------------------------------