Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Include user role in the export #5211

Closed
lenvanessen opened this issue Nov 6, 2019 · 2 comments
Closed

[RFC] Include user role in the export #5211

lenvanessen opened this issue Nov 6, 2019 · 2 comments

Comments

@lenvanessen
Copy link

@lenvanessen lenvanessen commented Nov 6, 2019

Description

You can export the users since 3.2 I believe, which is great for Audit purposes. Would it be possible to add a column to the export with the roles?

@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Nov 6, 2019

We will be making a few improvements to element exporting in Craft 3.4, so I’ll add this to the list.

@brandonkelly brandonkelly added this to the 3.4 milestone Nov 6, 2019
brandonkelly added a commit that referenced this issue Dec 10, 2019
Resolves #5090
Resolves #4484
Resolves #4561
Resolves #5211
@brandonkelly

This comment has been minimized.

Copy link
Member

@brandonkelly brandonkelly commented Dec 10, 2019

As of Craft 3.4 it will be possible to register custom element export types, so you can include whatever data you want in those. (See #5090 (comment).)

// -- Module.php
use craft\elements\User;
use craft\events\RegisterElementExportersEvent;
use yii\base\Event;

Event::on(User::class, Entry::EVENT_REGISTER_EXPORTERS, function(RegisterElementExportersEvent $e) {
    $e->exporters[] = MyUserExporter::class;
});
// -- MyUserExporter.php
use craft\base\ElementExporter;
use craft\elements\User;
use craft\elements\db\ElementQueryInterface;

class MyUserExporter extends ElementExporter
{
    public static function displayName(): string
    {
        return 'User data';
    }

    public function export(ElementQueryInterface $query): array
    {
        $data = [];

        foreach ($query->each() as $user) {
            $data[] = $user->toArray([], ['groups']);
        }

        return $data[];
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.