You are here

function popup_onload_prepare_popup in Popup On Load 8

Same name and namespace in other branches
  1. 7 popup_onload.module \popup_onload_prepare_popup()

Generate Javascript parameters for popup.

Parameters

object $popup_onload: Fully populated popup_onload entity.

Return value

array Popup javascript settings

1 call to popup_onload_prepare_popup()
PopupOnloadController::getPopup in src/Controller/PopupOnloadController.php
Get popup.

File

./popup_onload.module, line 154
Contains main popup_onload hooks and functions.

Code

function popup_onload_prepare_popup($popup_onload) {
  $popup_markup = \Drupal::entityTypeManager()
    ->getViewBuilder('popup_onload')
    ->view($popup_onload);
  $renderer = \Drupal::service('renderer');
  $popup_settings = array(
    'html' => $renderer
      ->renderRoot($popup_markup)
      ->__toString(),
    'delay' => PopupOnLoadSettingsForm::popupOnLoadGetDefaults(POPUP_ONLOAD_VAR_DISPLAY_DELAY, POPUP_ONLOAD_DEFAULT_DELAY),
    'popup_id' => $popup_onload
      ->id(),
    'dialogClass' => 'popup-onload-dialog',
    'title' => $popup_onload
      ->get('name')->value,
    'close' => '',
    'cookie_name' => PopupOnLoadSettingsForm::popupOnLoadGetDefaults(POPUP_ONLOAD_VAR_COOKIE_NAME, POPUP_ONLOAD_DEFAULT_COOKIE_NAME) . '_' . $popup_onload
      ->id(),
    'expire_seconds' => PopupOnLoadSettingsForm::popupOnLoadGetDefaults(POPUP_ONLOAD_VAR_COOKIE_LIFETIME, POPUP_ONLOAD_DEFAULT_COOKIE_LIFETIME),
  );
  if ($popup_onload
    ->get('width')->value) {
    $popup_settings['width'] = $popup_onload
      ->get('width')->value;
  }
  if ($popup_onload
    ->get('height')->height) {
    $popup_settings['height'] = $popup_onload
      ->get('height')->height;
  }

  // Let other modules alter popup settings.
  \Drupal::moduleHandler()
    ->alter('popup_onload_js_settings', $popup_settings, $popup_onload);
  return $popup_settings;
}