Hi, with the lastest dev version when I use serialization programmatically i get this error
Error: Call to a member function getDisplay() on null in Drupal\csv_serialization\Encoder\CsvEncoder->extractHeaders() (lin

here my code to serialize :

      $encoders = [new CsvEncoder($delimiter, $enclosure, $escape_char)];
      $serializer = new Serializer([], $encoders);
$row_csv= $serializer->serialize([$row_normalize], 'csv') . PHP_EOL;

Comments

Musa.thomas created an issue. See original summary.

musa.thomas’s picture

ramya balasubramanian’s picture

Status: Active » Reviewed & tested by the community

Hi Musa.thomas,

I have applied this patch and its working fine . Thanks

DustinSwede’s picture

This patch works stops the crash however the headers no longer show up in the output. (The 1.0.0 version of this module had the headers)

c-logemann’s picture

Assigned: Unassigned » c-logemann
Priority: Normal » Major
Status: Reviewed & tested by the community » Needs work
Related issues: +#2772937: Headings in csv have machine names

I can confirm this issue when using this module with Contact Storage Export which does not provide a view in context. The possibility to use a context was implemented with #2772937: Headings in csv have machine names. But this implementation breaks the API so I set this bug priority to "major".

The patch #2 is avoiding the call of "getDisplay()" but does not provide any headers any more as reported by DustinSwede in #4.

I will provide a patch in my next comment.

c-logemann’s picture

Patch to avoid the call of "getDisplay()" if view context isn't available and still provides header.

c-logemann’s picture

Status: Needs work » Needs review
c-logemann’s picture

Title: Use csv encoder programatically trigger fatal error » Fatal error when using CSV Encoder without views context
Assigned: c-logemann » Unassigned
qudec’s picture

I used 6.patch with contact_storage_export module, works perfectly.

berdir’s picture

Priority: Major » Critical
Status: Needs review » Reviewed & tested by the community

Can confirm the problem, I'd even say this is critical as it is a regression and easy to reproduce fatal error when not using a view.

inversed’s picture

I needed this to get the Contact Storage Export module working. Patch #6 solved the problem right away.

andrej galuf’s picture

Patch #6 confirmed as working. Priority is definitely Critical, as Berdir stated, as it breaks on custom csv exporters that aren't based on Views.

  • grasmash committed be52d4e on 8.x-1.x authored by C_Logemann
    Issue #2916034 by C_Logemann, Musa.thomas: Fatal error when using CSV...
grasmash’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.