Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/install/openy_map.settings.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
map_engine: leaflet
noscript_text:
value: 'This map shows location pins for nearby locations. To use it, please enable JavaScript in your browser.'
format: plain_text
distance_limit_units: ml
leaflet:
base_layer: OpenStreetMap.Mapnik
Expand Down
11 changes: 11 additions & 0 deletions config/schema/openy_map.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ openy_map.settings:
type: config_object
label: 'Openy Map Settings'
mapping:
noscript_text:
type: mapping
label: 'No-script message'
mapping:
value:
type: text
label: 'Text'
translatable: true
format:
type: string
label: 'Text format'
default_tags:
type: sequence
label: 'Default Tags'
Expand Down
3 changes: 3 additions & 0 deletions css/map.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.openy-map-canvas {
height: 300px;
width: auto;
display: flex;
justify-content: center;
align-items: center;
}
19 changes: 16 additions & 3 deletions openy_map.install
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ function openy_map_update_8006() {
$openy_map_config_leaflet_base_layer = $config_factory->getEditable('openy_map.settings')->get('leaflet.base_layer');
if ($openy_map_config_leaflet_base_layer == 'Wikimedia'){
$config_factory->getEditable('openy_map.settings')
->set('leaflet.base_layer', 'OpenStreetMap.Mapnik')
->save(TRUE);
->set('leaflet.base_layer', 'OpenStreetMap.Mapnik')
->save(TRUE);
}
}

/**
/**
* Update path to icons.
*/
function openy_map_update_8007() {
Expand All @@ -154,3 +154,16 @@ function openy_map_update_8008() {
function openy_map_update_8009() {
_openy_map_absolutize_config_icon_urls();
}

/**
* Add noscript_text configuration.
*/
function openy_map_update_8010() {
$config = \Drupal::configFactory()->getEditable('openy_map.settings');
if ($config->get('noscript_text') === NULL) {
$config->set('noscript_text', [
'value' => 'This map shows location pins for nearby locations. To use it, please enable JavaScript in your browser.',
'format' => 'plain_text',
])->save(TRUE);
}
}
4 changes: 4 additions & 0 deletions src/Element/OpenYMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static function processElement(array $element) {
break;
}
$element['#attached']['drupalSettings']['openyMap'] = $element['#element_variables'];
$noscript = $settings->get('noscript_text');
if (!empty($noscript['value'])) {
$element['#noscript_text'] = check_markup($noscript['value'], $noscript['format'] ?? 'plain_text');
}
$tags = $settings->get('default_tags');
$element['#attached']['drupalSettings']['openyMapSettings']['default_tags'] = array_values(array_filter($tags));
$element['#cache']['tags'][] = 'config:openy_map.settings';
Expand Down
10 changes: 10 additions & 0 deletions src/Form/SettingsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('openy_map.settings');
$form_state->setCached(FALSE);

$noscript = $config->get('noscript_text');
$form['noscript_text'] = [
'#type' => 'text_format',
'#title' => $this->t('No-script message'),
'#description' => $this->t('Message shown inside a <noscript> tag when JavaScript is disabled. Displayed in place of the map canvas.'),
'#default_value' => $noscript['value'] ?? $this->t('This map shows location pins for nearby locations. To use it, please enable JavaScript in your browser.'),
'#format' => $noscript['format'] ?? 'plain_text',
];

$form['map_engine_title'] = [
'#markup' => '<h2>' . $this->t('Map provider') . '</h2>',
];
Expand Down Expand Up @@ -348,6 +357,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$type_icons[$id] = $form_state->getValue($id . '_icon');
}

$config->set('noscript_text', $form_state->getValue('noscript_text'));
$config->set('map_engine', $form_state->getValue('map_engine'));
$config->set('distance_limit_units', $form_state->getValue('distance_limit_units'));
$config->set('leaflet.location', $form_state->getValue('leaflet')['location']);
Expand Down
6 changes: 5 additions & 1 deletion templates/openy-map.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<div class="openy-map-wrapper">
<div class="openy-map-canvas openy-map map"></div>
<div class="openy-map-canvas openy-map map" aria-hidden="true">
{% if element['#noscript_text'] %}
<noscript>{{ element['#noscript_text'] }}</noscript>
{% endif %}
</div>
{% if element['#show_controls'] %}
<div class="row">
<div class="map_controls col-lg-12">
Expand Down