heimrichhannot / contao-exporter-bundle

A backend module for exporting any contao entity to file.
1 stars 2 forks source link

Hook huh.exporter.event.modifyfieldvalue dows not work as expected #8

Closed cmette closed 2 years ago

cmette commented 2 years ago

I am trying to use the hook huh.exporter.event.modifyfieldvalue but it is not working as expected. I am using the EventSubscriber pattern with Symfony 4.3 and Contao 4.9.22.

class HuhExporterEventModifyFieldValue implements EventSubscriberInterface
{
    public static function getSubscribedEvents()
    {
        // return the subscribed events, their methods and priorities
        return [
            ModifyFieldValueEvent::NAME => 'onEvent'
        ];
    }

    public function onEvent(ModifyFieldValueEvent &$event)
    {
        $row = $event->getRow();
        $row['tl_user.name'] = '0';
        $event->setRow($row);
    }
}

The function is called correctly, but this has no effect on the spreadsheet. The exported spreadsheet is not modified at any time.

Do you have any suggestions?

With kind regards!

Defcon0 commented 2 years ago

Did you try registering an event listener rather than a subscriber?

koertho commented 2 years ago

@Defcon0 This shouldn't have an impact.

Defcon0 commented 2 years ago

I know, just curious

Defcon0 commented 2 years ago

Ah, you just used the wrong method for propagating back to the event class:

https://github.com/heimrichhannot/contao-exporter-bundle/blob/master/src/Exporter/AbstractPhpSpreadsheetExporter.php#L99

value is the property you like to adjust, not row ;-) Because you registered a ModifyField*Value* subscriber ;-)

cmette commented 2 years ago

Thanks a lot for the quick answer! That works!