kml.module in KML 8
Same filename and directory in other branches
Adds support for serializing entities to KML.
File
kml.moduleView source
<?php
/**
* @file
* Adds support for serializing entities to KML.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function kml_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.kml':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This module allows for export of location-specific data as placemarks in KML and KMZ formats.') . '</p>';
return $output;
}
}
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_form_BASE_FORM_ID_alter().
*/
function kml_form_views_ui_edit_display_form_alter(&$form, FormStateInterface $form_state, $form_id) {
if (isset($form['options']['style_options']['formats']['#options']) && in_array('kml', $form['options']['style_options']['formats']['#options'])) {
/** @var \Drupal\views\Entity\View $view */
$view = $form_state
->getStorage()['view'];
$display = $view
->getExecutable()
->getDisplay();
// KML options.
$form['options']['style_options']['kml_settings'] = [
'#type' => 'details',
'#open' => FALSE,
'#title' => t('KML settings'),
'#states' => [
'visible' => [
[
':input[name="style_options[formats][kml]"]' => [
'checked' => TRUE,
],
],
'or',
[
':input[name="style_options[formats][kmz]"]' => [
'checked' => TRUE,
],
],
],
],
'kml_header' => [
'#type' => 'textarea',
'#title' => t('KML Document header'),
'#description' => t('What goes here will be inserted between the <Document> tag and the first <Placemark> tag. Must be valid KML. Can include <name>, <description>, <atom:author>, style table etc.'),
'#default_value' => $display->display['display_options']['style']['options']['kml_settings']['kml_header'],
],
];
}
if (isset($form['options']['row_options']['field_options'])) {
/** @var \Drupal\views\Entity\View $view */
$view = $form_state
->getStorage()['view'];
$display = $view
->getExecutable()
->getDisplay();
if (isset($display->display['display_options']['style']['options']['formats']['kml']) || isset($display->display['display_options']['style']['options']['formats']['kmz'])) {
foreach ($form['options']['row_options']['field_options']['#header'] as &$header) {
if ($header
->getUntranslatedString() === 'Alias') {
$header = t('KML Tag');
}
}
foreach ($form['options']['row_options']['field_options'] as $key => &$field_option) {
if (strpos($key, '#') !== 0) {
$field_option['alias']['#type'] = 'select';
$field_option['alias']['#options'] = [
'name' => 'name',
'description' => 'description',
'Point_coordinates' => 'Point_coordinates',
'LineString_coordinates' => 'LineString_coordinates',
'icon' => 'icon',
'styleUrl' => 'styleUrl',
'atom_author' => 'atom_author',
'atom_link' => 'atom_link',
'gx_media_links' => 'gx_media_links',
'Folder' => 'Folder',
];
$field_option['alias']['#empty_option'] = t('Preformatted KML');
}
}
}
}
}
Functions
Name | Description |
---|---|
kml_form_views_ui_edit_display_form_alter | Implements hook_form_BASE_FORM_ID_alter(). |
kml_help | Implements hook_help(). |