Follow-up to #2853756: Consider changing the way values are flattened before passed to the CSV Encoder to provide better data per column

Problem/Motivation

#2853756: Consider changing the way values are flattened before passed to the CSV Encoder to provide better data per column is going to improve CSV formatting by using default field formatters to render a value.

@Berdir suggested in #2853756.5 to provide a custom a view mode in order to improve export configurability per contact form.

wondering if we want to do something like token.module. Support a contact_storage_export view mode that you can enable and configure per contact form and fall back to the default settings. Also, don't we get labels if we do it like this, or are you working around that by rendering each item separately?

See field_tokens()

Proposed resolution

Add a contact_storage_export view mode and use its configuration in ContactStorageExportService::getFormattedValue().

The view mode should be optional to enable and fall back to the current output if not set.

Think about removing date_format setting as it is going to be configurable per field.

Remaining tasks

Comments

mbovan created an issue. See original summary.

scott_euser’s picture

This sounds like an interesting idea. Part of the goal of this module is to keep it usable at a basic level without the need for configuration per form (ie, if someone creates a new form, export should just be available straight away without needing special configuration).

Would that still be the case with your proposal?

Otherwise for a more developer focused solution, as outlined in https://www.drupal.org/project/contact_storage you do have 'CSV serialization to build views to export results' listed on the project page right?

The end-user (eg, client) should still be able to:

  • Exclude certain fields (ie, exclude fields not hidden in the view mode)
  • See labels at the top of their export

without having to have admin access or special training.

scott_euser’s picture

Issue summary: View changes

Ah I see Berdir's comment:

contact_storage_export view mode that you can enable and configure per contact form and fall back to the default settings

scott_euser’s picture

Priority: Normal » Minor

At the moment this is not a priority on my list - if someone would like this feature I would be happy if someone would be willing to help with a patch.

steven jones’s picture

Priority: Minor » Normal
Status: Active » Needs review
StatusFileSize
new1.08 KB

Here's a patch that provides an export view mode, and uses it.
This won't change the exports unless administrators also create custom settings for the export view mode for their contact forms, so keeps this module's sense of zero-configuration, whilst still allowing configuration.

Status: Needs review » Needs work
steven jones’s picture

Status: Needs work » Needs review
StatusFileSize
new1.62 KB

Ah, that totally broke the export of non-field fields.
Here's a fix for that.

Status: Needs review » Needs work
james.williams’s picture

StatusFileSize
new1.61 KB

Re-rolled patch. Note that these patches all depend on those in #2992265: Exported fields are in jumbled order which adds the use statement for \Drupal\Core\Entity\Entity\EntityViewDisplay. That's probably not ideal, but I should think the two would probably usually get used together anyway.