vojtasvoboda / oc-userimportexport-plugin

User import export plugin for OctoberCMS
MIT License
12 stars 6 forks source link

add settings model with option for overriding import/export config #13

Closed therealkevinard closed 4 years ago

therealkevinard commented 4 years ago

Provide a backend config option to allow end-users to inject custom $importExportConfig.

RainLab/User might be the most extended plugin on the market. This config allows a (fairly advanced) feature for overriding the default import/export config.

Example Usage: Customized Export

export: title: Export Users modelClass: VojtaSvoboda\UserImportExport\Models\UserExportModel list: $/my/plugin/vojtasvoboda_userimportexport/userexport_columns.yaml # uses customized config for export redirect: rainlab/user/users

- add a custom `userexport_columns.yaml`

===================================

Column Definitions

===================================

columns:

id: label: Id invisible: true

username: label: rainlab.user::lang.user.username searchable: true invisible: true

name: label: rainlab.user::lang.user.name searchable: true

surname: label: rainlab.user::lang.user.surname searchable: true invisible: true

email: label: rainlab.user::lang.user.email searchable: true

// Custom fields added elsewhere address_1: label: Address address_2: label: Address 2 city: label: City state_region: label: State postcode: label: Zip Code country: label: Country membership_payment_source: label: Source member_status: label: Status


- In October backend/admin navigate to `/system/settings/update/vojtasvoboda/userimportexport/config` and add `$/my/plugin/vojtasvoboda_userimportexport/config_import_export.yaml` as the custom override. 
vojtasvoboda commented 4 years ago

Hello @therealkevinard, thank you for your contribution.

I think the correct way how to extend plugin is described here: https://octobercms.com/docs/plugin/extending

Try to use something like that:

Event::listen('backend.form.extendFields', function ($widget) {
    if (!$widget->getController() instanceof UserImportExport) {
        return;
    }

    if (!$widget->model instanceof UserExportModel) {
        return;
    }

    $controler = $widget->getController();
});

Also check my overriding example repository, where you can find handy addColumns and addFields method: https://github.com/vojtasvoboda/oc-brands-plugin-override-example

Good luck, Vojta.

therealkevinard commented 4 years ago

Okay, fair enough :) I didn't realize the traditional extend would work for this as well.

I take back my PR.