diff --git a/src/Lightbox.php b/src/Lightbox.php index 93f2c03..ab0236b 100644 --- a/src/Lightbox.php +++ b/src/Lightbox.php @@ -7,6 +7,9 @@ class Lightbox extends Widget { + /** + * @var array containing the attributes for the images + */ public $files = []; public function init() { @@ -15,19 +18,26 @@ public function init() { public function run() { $html = ''; - foreach($this->files as $file) { - if(!isset($file['thumb']) || !isset($file['original'])) { + foreach ($this->files as $file) { + if (!isset($file['thumb']) || !isset($file['original'])) { continue; } - $img = Html::img($file['thumb']); - $a = Html::a($img, $file['original'], [ - 'data-lightbox' => 'image-' . uniqid(), + $attributes = [ 'data-title' => isset($file['title']) ? $file['title'] : '', - ]); + ]; + + if (isset($file['group'])) { + $attributes['data-lightbox'] = $file['group']; + } else { + $attributes['data-lightbox'] = 'image-' . uniqid(); + } + + $img = Html::img($file['thumb']); + $a = Html::a($img, $file['original'], $attributes); $html .= $a; } return $html; } -} +} \ No newline at end of file