popup.module in Popup 8
Same filename and directory in other branches
Module file for Popup module.
File
popup.moduleView source
<?php
/**
* @file
* Module file for Popup module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Url;
/**
* @defgroup popup Popup
*/
/**
* Implements hook_toolbar().
*/
function popup_toolbar() {
// First, build an array of all popup modules and their routes.
// We resort to this hard-coded way so as not to muck up each popup module.
$popup_modules = _popup_toolbar_routes();
// Build a list of links for the menu.
$links = [];
foreach ($popup_modules as $module => $route) {
// Get the module info (title, description) from Drupal.
$info = system_get_info('module', $module);
// If there's no info, the popup isn't enabled, so don't display it.
if (!empty($info)) {
$links[$module] = [
'title' => Html::escape($info['name']),
'url' => Url::fromRoute($route),
'attributes' => [
'title' => Html::escape($info['description']),
],
];
}
}
// Add a link to enable all popup modules.
$links['enable_popup'] = [
'title' => t('Enable Popup Modules'),
'url' => Url::fromRoute('system.modules_list'),
'options' => [
'title' => t('Enable more Popup modules in on the Extend page.'),
],
'fragment' => 'edit-modules-popup-modules',
];
// Create the Popup toolbar render array.
$items['popup_modules'] = [
'#type' => 'toolbar_item',
'tab' => [
'#type' => 'link',
'#title' => t('Popup'),
'#url' => Url::fromRoute('<front>'),
'#attributes' => [
'title' => t('Popup Modules'),
'class' => [
'toolbar-icon',
'toolbar-icon-popup',
],
],
],
'tray' => [
'#heading' => t('Popup Modules'),
'shortcuts' => [
'#theme' => 'links__toolbar_popup',
'#links' => $links,
'#attributes' => [
'class' => [
'toolbar-menu',
],
],
],
],
'#weight' => 99,
'#attached' => [
'library' => [
'popup/assets/images',
],
],
];
return $items;
}
/**
* Get a list of toolbar links to provide.
*
* We've factored this list into a function so that we can use it to test
* toolbar routes.
*
* This function is for internal use.
*
* @return string[]
* Keyed array of toolbar routes. Keys are the module name which supplies the
* route.
*/
function _popup_toolbar_routes() {
return [
'popup' => 'popup.admin',
];
}
/**
* Implements hook_help().
*/
function popup_help($route_name, RouteMatchInterface $route_match) {
if ($route_name === 'help.page.popup') {
$readme_file = file_exists(__DIR__ . '/README.md') ? __DIR__ . '/README.md' : __DIR__ . '/README.txt';
if (!file_exists($readme_file)) {
return NULL;
}
$text = file_get_contents($readme_file);
if ($text && !\Drupal::moduleHandler()
->moduleExists('markdown')) {
return '<pre>' . $text . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()
->get('markdown.settings')
->getRawData();
$config = [
'settings' => $settings,
];
$filter = $filter_manager
->createInstance('markdown', $config);
return $filter
->process($text, 'en');
}
}
return NULL;
}
/**
* Implementation of hook_permission
*/
function popup_permission() {
return [
'administer popup elements' => [
'title' => t('Administer popup elements'),
'description' => t('Configure popup element behavior and default presentation.'),
],
];
}
/**
* @} End of 'defgroup popup'.
*/
/**
* Implementation of hook_init
*
* Adds popup Script, settings and Style
*
*/
/*function popup_init(){
$path = drupal_get_path('module', 'popup');
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// drupal_add_js(
// $path . '/popup.js',
// array('preprocess' => variable_get('popup-preprocess', FALSE))
// );
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// drupal_add_css($path . '/popup.css',
// array('preprocess' => variable_get('popup-preprocess', FALSE))
// );
$effects = \Drupal::moduleHandler()->invokeAll('popup_effects');
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// drupal_add_js(
// array(
// 'popup' => array(
// 'effects' => $effects,
// 'linger' => variable_get('popup-hover-linger', 250),
// 'delay' => variable_get('popup-hover-delay', 0)
// )
// ),
// 'setting'
// );
}*/
/**
* Implementation of hook_popup_effects
*
* This hook allows modules to supply Javascript methods for showing/hiding
* popups.
*
* @return a keyed array
*
* in the form:
*
* array(
* 'show' => array(
* 'effect-name' => 'javascript to show the popup',
* ...
* ),
* 'hide' => array(
* 'effect-name' => 'javascript to hide the popup'
* ...
* ),
* );
*
* The Javascript is executed within the context of the PopupElement wrapper
* ojbect. The following properties are available as JQuery objects:
*
* element: The popup element wrapper
* title: the title element of the popup
* body: the body element of the popup. Keep in mind that the body is no
* longer contained within the popup element wrapper, but within its
* own wrapper within the #popup-active-overlay element at the end
* of the HTML body.
* wrapper: Wrapper of the popup element body. This has the same id as the
* popup element, with "-active" appended.
* origin: Invisible div element prepended to the element wrapper, to
* establish the popup top/left offset in relation to the document.
*
*/
/*function popup_popup_effects(){
return array(
'show' => array(
'default' => "this.body.show();",
'fade' => "
if (this.opacity){
this.body.fadeTo('medium',this.opacity);
}else{
this.body.fadeIn('medium');
}",
'slide-down' => "this.body.slideDown('medium')",
'slide-down-fade' => "
this.body.animate(
{
height:'show',
opacity:(this.opacity ? this.opacity : 'show')
}, 'medium'
);",
),
'hide' => array(
'default' => "this.body.hide();",
'fade' => "this.body.fadeOut('medium');",
'slide-down' => "this.body.slideUp('medium');",
'slide-down-fade' => "
this.body.animate(
{
height:'hide',
opacity:'hide'
}, 'medium'
);",
),
);
}*/
/**
* @FIXME
* This implementation of hook_menu() cannot be automatically converted because
* it contains logic (i.e., branching statements, function calls, object
* instantiation, etc.) You will need to convert it manually. Sorry!
*
* For more information on how to convert hook_menu() to Drupal 8's new routing
* and linking systems, see https://api.drupal.org/api/drupal/core%21includes%21menu.inc/group/menu/8
*/
/*function popup_menu(){
$path = drupal_get_path('module', 'popup');
return array(
'admin/config/user-interface/popup' => array(
'access arguments' => array('administer popup elements'),
'description' => t('Configure popup element behavior and default presentation.'),
'file' => 'popup.admin.inc',
'file path' => $path . '/includes',
'page arguments' => array('popup_admin_settings'),
'page callback' => 'drupal_get_form',
'title' => 'Popup elements',
'type' => MENU_NORMAL_ITEM,
),
'ahah/popup' => array(
'access arguments' => array('access content'),
'file' => 'popup.util.inc',
'file path' => $path . '/includes',
'page callback' => 'popup_get_ahah',
'type' => MENU_CALLBACK,
),
);
}*/
/**
* Implementation of hook_theme
*/
/*function popup_theme(){
module_load_include('inc', 'popup', 'includes/popup.theme');
module_load_include('inc', 'popup', 'includes/popup.util');
$styles = _popup_styles();
$theme = _popup_theme_array();
foreach($styles as $style => $path){
$theme += _popup_theme_array(_popup_title_to_key($style), $path);
}
$theme += array(
'popup_ahah_placeholder' => array(
'variables' => array(
'type' => '',
'attributes' => array(),
),
'file' => 'includes/popup.theme.inc',
),
);
return $theme;
}*/
/**
* Implementation of hook_popup_styles
*
* This hook allows modules to provide popup display styles. Note that the
* templates of these styles cannot be overridden by the theme.
*
* @return a keyed array
*
* in the form:
*
* array(
* 'Style name 1' => 'path/to/style-1',
* 'Style label 2' => 'path/to/style-2',
* ...
* )
*
* For style-1 the following files must exist in the path/to/style-1 directory:
*
* popup-element-body.tpl.php
* popup-element-title.tpl.php
* popup-element.tpl.php
*
* For style-1 the following files may exist in the path/to/style-1 directory,
* and will be included if present:
*
* popup-element.css
* popup-element.js
*
*/
/*function popup_popup_styles(){
$path = drupal_get_path('module', 'popup') . '/styles';
return array(
'McPopup' => $path . '/McPopup',
'Bent white' => $path . '/bent_white',
'Black' => $path . '/black',
'Obsidian' => $path . '/obsidian',
'White' => $path . '/white',
);
}*/
/**
* Implementation of hook_popup_attributes_alter to provide defaults
*/
/*function popup_popup_attributes_alter(&$attributes){
module_load_include('inc', 'popup', 'includes/popup.util');
$defaults = _popup_defaults();
$attributes = array_merge(
$defaults,
$attributes
);
}*/
/* ---- Preprocessors ---- */
/**
* Popup element preprocessor
*
* Adds CSS of the selected style
*
*/
/*function popup_preprocess_popup_element(&$variables){
module_load_include('inc', 'popup', 'includes/popup.util');
$styles = _popup_styles();
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// $style = isset($variables['style']) && $variables['style']
// ? $variables['style']
// : variable_get('popup-style', 'White');
$path = isset($styles[$style]) ? $styles[$style] : NULL;
$variables['classes_array'] = array();
$variables['attributes_array'] = array();
$variables['title_attributes_array'] = array();
$variables['content_attributes_array'] = array();
if (isset($path)) {
if (file_exists($path . '/popup-element.css')) {
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// drupal_add_css(
// $path . '/popup-element.css',
// array(
// 'media' => 'screen, projection',
// 'preprocess' => variable_get('popup-preprocess', FALSE),
// 'basename' => _popup_title_to_key($style) . '.popup-element.css',
// )
// );
}
if (file_exists($path . '/popup-element.js')){
// @FIXME
// // @FIXME
// // This looks like another module's variable. You'll need to rewrite this call
// // to ensure that it uses the correct configuration object.
// drupal_add_js(
// $path . '/popup-element.js',
// array(
// 'scope' => 'header',
// 'preprocess' => variable_get('popup-preprocess', FALSE),
// )
// );
}
}
}*/
Functions
Name | Description |
---|---|
popup_help | Implements hook_help(). |
popup_permission | Implementation of hook_permission |
popup_toolbar | Implements hook_toolbar(). |
_popup_toolbar_routes | Get a list of toolbar links to provide. |