mappy.module in Mappy 8
Same filename and directory in other branches
Main module file.
File
mappy.moduleView source
<?php
/**
* @file
* Main module file.
*/
/**
* Implements hook_page_build().
*/
function mappy_page_build(&$page) {
$config = \Drupal::config('mappy.settings');
// Patterns for matching.
$pages = drupal_strtolower($config
->get('loading.paths'));
// Convert path alias to lowercase.
$path = drupal_strtolower(\Drupal::service('path.alias_manager')
->getAliasByPath(current_path()));
// If path have not alias.
if (!$path) {
$path = current_path();
}
// Compare pages to aliased path.
$page_match = \Drupal::service('path.matcher')
->matchPath($path, $pages);
// Compare for original paths.
if ($path != current_path()) {
$page_match = $page_match || \Drupal::service('path.matcher')
->matchPath(current_path(), $pages);
}
// Type of the matching path.
// 0 - All pages except those listed.
// 1 - Only the listed pages.
$match_type = $config
->get('loading.type');
// First comparsion for 'All pages except those listed'.
// Second for 'Only the listed pages'.
if ($match_type == "0" && !$page_match || $match_type && $page_match) {
$page['#attached']['library'][] = 'mappy/mappy.mappy';
$page['#attached']['js'][] = [
'data' => [
'mappy' => [
'location' => drupal_get_path('module', 'mappy'),
'google' => [
'width' => $config
->get('google.width'),
'height' => $config
->get('google.height'),
],
'yandex' => [
'width' => $config
->get('yandex.width'),
'height' => $config
->get('yandex.height'),
'version' => $config
->get('yandex.version'),
],
],
],
'type' => 'setting',
];
}
}
Functions
Name | Description |
---|---|
mappy_page_build | Implements hook_page_build(). |