public function NgLightbox::addLightbox in NG Lightbox 8
Same name and namespace in other branches
- 2.x src/NgLightbox.php \Drupal\ng_lightbox\NgLightbox::addLightbox()
Adds a lightbox to a link.
Parameters
array $link: The link we want to add the lightbox to.
File
- src/
NgLightbox.php, line 135
Class
Namespace
Drupal\ng_lightboxCode
public function addLightbox(array &$link) {
// Safety check if class isn't an array.
if (!isset($link['options']['attributes']['class'])) {
$link['options']['attributes']['class'] = [];
}
// Add our lightbox class.
$link['options']['attributes']['class'][] = 'use-ajax';
$link['options']['attributes']['data-dialog-type'] = str_replace('drupal_', '', $this->config
->get('renderer') ?: static::DEFAULT_MODAL);
$data = [
'width' => $this->config
->get('default_width'),
'dialogClass' => $this->config
->get('lightbox_class'),
];
$link['options']['attributes']['data-dialog-options'] = json_encode($data);
}