Skip to content

Added “Display on“ options to Map element - #315

Merged
jekuaitk merged 13 commits into
OS2Forms:developfrom
itk-dev:feature/maps-element-display
Oct 27, 2026
Merged

jekuaitk merged 13 commits into
OS2Forms:developfrom
itk-dev:feature/maps-element-display

Conversation

@rimi-itk

@rimi-itk rimi-itk commented Mar 11, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #335

This is a follow-up on #289 (and hence related to https://os2forms-leantime.itkdev.dk/_#/tickets/showTicket/180).

Adds “Display … on” settings to Map element to control where the image and the GeoJSON are displayed:

Screen Shot 2026-03-11 at 09 39 00

Along the way the template/theme hack to display the image has been removed.

@rimi-itk
rimi-itk force-pushed the feature/maps-element-display branch from a334f6d to 3c9dffb Compare March 11, 2026 11:43
@rimi-itk
rimi-itk requested a review from jekuaitk March 11, 2026 11:43
@rimi-itk
rimi-itk requested a review from stankut March 12, 2026 08:21
@ds-bellcom

Copy link
Copy Markdown
Contributor

@rimi-itk jeg kan se at du har bedt Stan om at lave review på denne opgave, men jeg kan ikke se noget issue omkring det PR, så jeg ved ikke helt hvem der har bestilt opgaven og hvem der skal betale for review. Kan du gøre mig klogere?

@rimi-itk

rimi-itk commented Apr 9, 2026

Copy link
Copy Markdown
Collaborator Author

@ds-bellcom, jeg har tilføjet en henvisning til et tidligere pull request (og til Leantime) i beskrivelsen.

@ds-bellcom

Copy link
Copy Markdown
Contributor

@OS2Forms/koordinationsgruppe Inden vi kan planlægge at lave review på denne opgave, så vil jeg gerne have en godkendelse på opgaven. Jeg vil forvente at det kan klares på ca. 2 timer. Er det OK?

@ds-bellcom

Copy link
Copy Markdown
Contributor

@OS2Forms/koordinationsgruppe Inden vi kan planlægge at lave review på denne opgave, så vil jeg gerne have en godkendelse på opgaven. Jeg vil forvente at det kan klares på ca. 2 timer. Er det OK?

@OS2Forms/koordinationsgruppe kan de 2 timer godkendes?

$viewMode = 'pdf';
}

// @todo Is this (i.e. $element['#display_image_on']) really the way to get element configuration?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you forget to remove this TODO comment or it's left intentionally?

}

// @todo Is this (i.e. $element['#display_image_on']) really the way to get element configuration?
$showImageOn = array_filter((array) ($element['#display_image_on'] ?? NULL));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing map elements do not have #display_image_on checks resolve to false and the formatter returns an empty array. Since this PR also removes the previous template, existing submissions lose their map output after upgrading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map functionality has been broken since the Drupal 10 upgrade. Therefore there is no backwards compatibility.

$showImageOn = array_filter((array) ($element['#display_image_on'] ?? NULL));
$includeImage = isset($showImageOn[$viewMode]);

$showGeoJsonOn = array_filter((array) ($element['#display_geojson_on'] ?? NULL));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing map elements do not have #display_geojson_on, so both checks resolve to false and the formatter returns an empty array. Since this PR also removes the previous template, existing submissions lose their map output after upgrading

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The map functionality has been broken since the Drupal 10 upgrade. Therefore there is no backwards compatibility.


// @todo Is this (i.e. $element['#display_image_on']) really the way to get element configuration?
$showImageOn = array_filter((array) ($element['#display_image_on'] ?? NULL));
$includeImage = isset($showImageOn[$viewMode]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check selected values with in_array() rather than isset(): the defaults are numerically indexed lists, so checking keys such as html also fails.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to in_array() in combination with getElementProperty in fe4c04c.

$includeImage = isset($showImageOn[$viewMode]);

$showGeoJsonOn = array_filter((array) ($element['#display_geojson_on'] ?? NULL));
$includeGeoJson = isset($showGeoJsonOn[$viewMode]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need to check selected values with in_array() rather than isset(): the defaults are numerically indexed lists, so checking keys such as html also fails.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed by fe4c04c


$viewMode = $options['view_mode'] ?? 'results';
if ('table' === $viewMode) {
$viewMode = 'html';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a PDF uses the table layout, the options look like this

$options = [
  'view_mode' => 'table',
  'pdf' => TRUE,
];

Current version of the could would treats it as HTML and skips the PDF check. This means the PDF follows the HTML display settings instead of the PDF settings.

For example, an image enabled only for PDF will be missing from a PDF with a table layout. Please check the PDF/email flags before handling the table layout.

It's ok, if that's intentional though

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Reordered the checks in fe4c04c!

$value = $this->getMapValue($element, $webform_submission, $options);

return $value['geojson'];
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatTextItem() always returns GeoJSON without checking #display_geojson_on.

Unchecking “Text”, or disabling GeoJSON everywhere, therefore has no effect on text output. Please apply the configured display rules here as well, including the email context for plain-text emails.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing configuration display checks in fe4c04c!

@ds-bellcom

Copy link
Copy Markdown
Contributor

Please wait to merge this PR until the Drupal 11 release is out.

@ds-bellcom

Copy link
Copy Markdown
Contributor

@jekuaitk this PR may be merged to develop-branch when the corrections is made.

@jekuaitk
jekuaitk merged commit 8d7df5d into OS2Forms:develop Oct 27, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Display on" option for Map element

4 participants