Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
drupal/melt_modal / melt_modal.module
Size: Mime:
<?php

/**
 * @file
 * Contains melt_modal.module.
 */

use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function melt_modal_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    // Main module help for the melt_modal module.
    case 'help.page.melt_modal':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('Creates a sticky footer until element is scrolled into view') . '</p>';
      return $output;

    default:
  }
}

/**
 * Implements hook_theme().
 */
function melt_modal_theme() {
  return [
    'melt_modal' => [
      'render element' => 'children',
    ],
  ];
}

/**
 * Implements hook_page_attachments().
 */
function melt_modal_page_attachments(&$attachments) {

  // Exit if we're on an admin route.
  if (\Drupal::service('router.admin_context')->isAdminRoute()) {
    return FALSE;
  }

  /** @var \Drupal\Core\Config\Config $config */
  $config = \Drupal::config('melt_modal.modal');

  /** @var \Drupal\Core\Condition\ConditionManager $manager */
  $manager   = \Drupal::service('plugin.manager.condition');

  /** @var \Drupal\system\Plugin\Condition\RequestPath $condition */
  $condition = $manager->createInstance('request_path');

  $condition->setConfiguration($config->get('request_path'));

  // Enable sticky footer based on Page Visiblity settings found on the
  // configuration page.
  if (empty($config->get('request_path')['pages']) || $condition->evaluate()) {

    // Pass JS related files to front end if the Page restrictions
    // text area is empty or has paths which we'll treat as those
    // we don't want JS to run on.
    $attachments['#attached']['drupalSettings']['meltModal'] = [
      'modalId' => $config->get('extlink_modal_selector'),
      'continueId' => $config->get('extlink_continue_selector'),
      'whitelist' => $config->get('extlink_whitelist'),
    ];

    if ($config->get('extlink_enable')) {
      $attachments['#attached']['library'][] = 'melt_modal/externalLinks';
    }

    $attachments['#attached']['library'][] = 'melt_modal/main';

  }

}