popup_maker.module in Popup Maker - All popup types 8
Same filename and directory in other branches
This module holds functions for Popup Maker.
File
popup_maker.moduleView source
<?php
/**
* @file
* This module holds functions for Popup Maker.
*/
use Drupal\node\NodeInterface;
/**
* Implements hook_theme().
*/
function popup_maker_theme($existing, $type, $theme, $path) {
return [
'popup_maker_settings' => [
'variables' => [
'settings' => [],
'token' => NULL,
'edit' => FALSE,
'editingPopupId' => NULL,
'displayRules' => NULL,
],
'template' => 'popup-maker-settings',
],
'popup_maker_display_rule' => [
'variables' => [
'rule' => [],
'index' => '{index}',
'last' => FALSE,
'displayRules' => [],
],
'template' => 'display-rule.html.twig',
],
];
}
/**
* Page top function for the popup maker.
*/
function popup_maker_page_top(array &$page_top) {
$node = \Drupal::routeMatch()
->getParameter('node');
if (!$node instanceof NodeInterface) {
return;
}
$config = \Drupal::config('popup_maker.settings');
$popups = $config
->get('popups');
$popupSettings = $config
->get('popupSettings');
$template = '<script>
window.SGPMPopupLoader=window.SGPMPopupLoader||{ids:[],popups:{},call:function(w,d,s,l,id){
w[\'sgp\']=w[\'sgp\']||function(){(w[\'sgp\'].q=w[\'sgp\'].q||[]).push(arguments[0]);};
var sg1=d.createElement(s),sg0=d.getElementsByTagName(s)[0];
if(SGPMPopupLoader && SGPMPopupLoader.ids && SGPMPopupLoader.ids.length > 0){SGPMPopupLoader.ids.push(id); return;}
SGPMPopupLoader.ids.push(id);
sg1.onload = function(){SGPMPopup.openSGPMPopup();}; sg1.async=true; sg1.src=l;
sg0.parentNode.insertBefore(sg1,sg0);
return {};
}};';
if (empty($popups)) {
return;
}
foreach ($popups as $id => $popup) {
if (!$popupSettings[$id]['enabled']) {
continue;
}
$allowed = TRUE;
if (!empty($popupSettings[$id]['displayOptions'])) {
$allowed = FALSE;
foreach ($popupSettings[$id]['displayOptions'] as $displayOption) {
if (strpos($displayOption['param'], '_all')) {
$endIndex = strpos($displayOption['param'], '_all');
$contentType = substr($displayOption['param'], 0, $endIndex);
$currentContentType = $node
->getType();
if ($displayOption['operator'] === '==') {
if ($currentContentType === $contentType) {
$allowed = TRUE;
}
}
elseif ($currentContentType !== $contentType) {
$allowed = TRUE;
}
}
elseif (strpos($displayOption['param'], '_selected')) {
$values = $displayOption['value'];
if ($displayOption['operator'] === '==') {
if (in_array($node
->id(), $values)) {
$allowed = TRUE;
}
}
elseif (!in_array($node
->id(), $values)) {
$allowed = TRUE;
}
}
}
}
if ($allowed) {
$template .= "SGPMPopupLoader.call(window,document,'script','https://popupmaker.com/assets/lib/SGPMPopup.min.js','" . $popup['hashId'] . "');";
}
}
$template .= '</script>';
$page_top['popup_maker'] = [
'#type' => 'inline_template',
'#template' => $template,
];
}
Functions
Name | Description |
---|---|
popup_maker_page_top | Page top function for the popup maker. |
popup_maker_theme | Implements hook_theme(). |