Dynamic Filename Specification for Export Actions

Currently, I leverage the getOptionsFormComponents() method to allow users to customize their export options, such as limiting column content. However, I noticed that while we can access these options in closure functions (like formatStateUsing), there's no direct, built-in method to apply these options to modify the exported file's name dynamically based on user input.

What I'm Looking to Achieve:

I wish to present a text input to users where they can specify a custom filename for their export file before initiating the export process. The goal is to directly use this user-specified filename for the export without resorting to workarounds such as session storage or predefined naming conventions.

Suggestion:

Would it be possible to introduce functionality or a method within the exporter class where $options could directly influence the getFileName method? For example, allowing getFileName to access $options provided through getOptionsFormComponents() would be incredibly beneficial.

Example Use Case:

public static function getOptionsFormComponents(): array {
    return [
        TextInput::make('fileName')
            ->label('Custom Filename'),
    ];
}

// Ideally accessing options in getFileName or a similar approach
public function getFileName($export, $options): string {
    return $options['fileName'] ?? 'default_name' . '.xlsx';
}


I also could be overlooking a way to do this with current functionality.
Solution
Putting this in your own Exporter class seems to do the job & allow users to name their own export files:

public function getFileName(Export $export): string
    {
        $filename = $this->options['fileName'] ?? 'default_export_filename';
        return $filename;
    }

    public static function getOptionsFormComponents(): array
    {
        return [
            TextInput::make('fileName')
                ->label('What would you like to name your export?'),
        ];
    }
Was this page helpful?