kunicmarko20 / SonataImporterBundle

Easier handling of Import in Sonata Admin.
MIT License
4 stars 3 forks source link

Import action breaks non-import admins #2

Closed vstanchev closed 4 years ago

vstanchev commented 4 years ago

The method AdminImportExtension::configureActionButtons does not check if the current $admin implements the AdminWithImport interface and alwasy adds the import action. This breaks admins for which an import does not exist with an exception similar to

An exception has been thrown during the rendering of a template ("unable to find the route admin.company.import").

Proposed resolution is to check if $admin implements the import interface as follows:

public function configureActionButtons(AdminInterface $admin, $list, $action, $object): array
    {
        if (!$admin instanceof AdminWithImport) {
            return $list;
        }

        $list['import']['template'] = $this->templates['action_button'];

        return $list;
    }
kunicmarko20 commented 4 years ago

Sounds like a good solution, could you provide a pr for this? Tbh, didn't use this library in a while.