View source
<?php
include 'openlayers_services.helpers.inc';
function openlayers_services_ctools_plugin_api($owner, $api) {
if ($owner == 'services' && $api == 'services') {
return array(
'version' => 3,
);
}
}
function openlayers_services_services_resources() {
return array(
'openlayers-map' => array(
'retrieve' => array(
'help' => 'Retrieves an Openlayers map',
'file' => array(
'type' => 'inc',
'module' => 'openlayers_services',
'name' => 'openlayers_services.services',
),
'callback' => '_openlayers_services_retrieve',
'access callback' => '_openlayers_services_access',
'access arguments' => array(
'view',
),
'access arguments append' => TRUE,
'args' => array(
array(
'name' => 'name',
'type' => 'string',
'description' => 'The name of the map to get',
'source' => array(
'path' => '0',
),
'optional' => FALSE,
),
),
),
),
);
}
function openlayers_services_theme($existing, $type, $theme, $path) {
return array(
'openlayers_map_iframe' => array(
'arguments' => array(
'page' => '',
'scripts' => '',
'styles' => '',
),
'template' => 'openlayers-map--iframe',
'path' => $path . '/themes',
),
);
}
function openlayers_services_form_openlayers_map_form_settings_alter(&$form, &$form_state) {
if (($map = \Drupal\openlayers\Openlayers::load('map', $form_state['item'])) == TRUE) {
$form['options']['ui']['provideIframe'] = array(
'#type' => 'checkbox',
'#title' => 'Provide iframe of this map ?',
'#description' => t('Enable this to provide this map as an iframe through the service module.'),
'#default_value' => $map
->getOption('provideIframe', FALSE),
'#parents' => array(
'options',
'provideIframe',
),
);
}
}
function openlayers_services_form_openlayers_map_form_preview_alter(&$form, &$form_state) {
$map = \Drupal\openlayers\Openlayers::load('map', $form_state['item']);
if ($map == FALSE || (bool) $map
->getOption('provideIframe', FALSE) == FALSE) {
return;
}
$form['information']['openlayers_services'] = array(
'#weight' => 10,
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => 'Embed this map in an iframe',
);
foreach (services_endpoint_load_all() as $service) {
if (isset($service->resources['openlayers-map']['operations']['retrieve']['enabled']) && $service->resources['openlayers-map']['operations']['retrieve']['enabled'] == 1) {
$width = $map
->getOption('width', 'auto') == 'auto' ? '100%' : $map
->getOption('width', 'auto');
$height = $map
->getOption('height', 'auto');
$iframe = "<iframe src='" . url('openlayers/openlayers-map/' . $map
->getMachineName(), array(
'absolute' => TRUE,
)) . "' width='" . $width . "' height='" . $height . "'/>";
$form['information']['openlayers_services'][$map
->getMachineName()] = array(
'#type' => 'textarea',
'#description' => t('Copy paste this html code to embed this map in your content.'),
'#rows' => 3,
'#value' => $iframe,
'#disabled' => FALSE,
);
}
}
}