kunicmarko20 / sonataimporterbundle Goto Github PK
View Code? Open in Web Editor NEWEasier handling of Import in Sonata Admin.
License: MIT License
Easier handling of Import in Sonata Admin.
License: MIT License
1 Why in sonata method before not exists.
2 Is possible to get in
public function map(array $item, array $additionalData)
item is
=> array:2 [▼
0 => "name"
1 => "description"
i preffer - use first row as key names and get assoc array key=>value
here is my example file
name | description |
---|---|
audi | audi desc |
BMW | desc bmw |
is possble to configure it in this way ?
The service "KunicMarko\SonataImporterBundle\Controller\ImportCRUDController" has a dependency on a non-existent service "KunicMarko\Importer\ImporterFactory.
PHP 7.2 - Symfony 4.1
Best regards
Q | A |
---|---|
Version | 0.1.2 |
Hello there, @kunicmarko20.
I have installed version 0.1.2 successfully on my application and now the button shows up on my admin page.
But when I click in this button, i receive a
Uncaught PHP Exception ReflectionException: "Method importAction does not exist" at /vendor/sensio/framework-extra-bundle/EventListener/ControllerListener.php line 58 {"exception":"[object] (ReflectionException(code: 0): Method importAction does not exist at /vendor/sensio/framework-extra-bundle/EventListener/ControllerListener.php:58)"} []
My admin class looks like:
use Sonata\AdminBundle\Admin\AbstractAdmin;
...
use KunicMarko\SonataImporterBundle\Admin\AdminWithImport;
class ListingAdmin extends AbstractAdmin implements AdminWithImport
{
...
}
I have no AdminController defined, so I have used the https://github.com/kunicmarko20/SonataImporterBundle/tree/0.1.2#prepare-controller config
I have already created a ListingCSVImportConfiguration class src/Cocorico/CoreBundle/Importer/ListingCSVImportConfiguration.php
but couldn't link it with my Admin class and didn't find a way to do it.
The ListingCSVImportConfiguration content is:
use Cocorico\CoreBundle\Admin\ListingAdmin;
use Cocorico\CoreBundle\Model\Manager\ListingManager;
use Cocorico\CoreBundle\Entity\Listing;
use KunicMarko\SonataImporterBundle\SonataImportConfiguration;
class ListingCSVImportConfiguration implements SonataImportConfiguration
{
protected $lem;
public function __construct(ListingManager $lem)
{
$this->lem = $lem;
}
public static function adminClass(): string
{
return ListingAdmin::class;
}
public static function format(): string
{
return 'csv';
}
public function map(array $item, array $additionalData)
{
$listing = new Listing();
$listing->setName($item[0]);
$this->lem->save($listing);
}
public function save(array $items, array $additionalData): void
{
$this->lem->save();
}
}
I propose to add visible configuration - preferred method in admin - isImportEnabled()
i can check user ROLE and then decide show import or not. Now is not easy remove import action because its add after admin configure routes / panel actions.
thanks
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;
}
Getting the following error when trying to install on Symfony 4.4:
The service "KunicMarko\SonataImporterBundle\Controller\ImportCRUDController" has a dependency on a non-existent service "KunicMarko\Importer\ImporterFactory".
Q | A |
---|---|
Version | 0.1.1 |
Hello there,
I am trying to install this package on a version of Cocorico and everytime I run my composer install, i receive the following error:
Fatal error: Uncaught Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "getRootNode" of class "Symfony\Component\Config\Definition\Builder\TreeBuilder". in vendor/kunicmarko/sonata-importer-bundle/src/DependencyInjection/Configuration.php on line 19
Symfony\Component\Debug\Exception\UndefinedMethodException: Attempted to call an undefined method named "getRootNode" of class "Symfony\Component\Config\Definition\Builder\TreeBuilder". in vendor/kunicmarko/sonata-importer-bundle/src/DependencyInjection/Configuration.php on line 19
This only happens when I try to use new KunicMarko\SonataImporterBundle\SonataImporterBundle(),
on my AppKernel.php.
Could you help me out with this?
I have problems with setup.
(Symfony 4.4, Sonata admin 3.55.0)
AutoConfigure ImportConfiguration
To be able to auto-configure your ImportConfiguration they will have to implement KunicMarko\SonataImporterBundle\SonataImportConfiguration and configure format and adminClass methods along with other methods.
I add to admin implements AdminWithImport
I add to controller trait and implement interface
class MyCrudController extends BaseController implements ControllerWithImport
{
use ImportActionTrait;
but i dont understand what now.
"To be able to auto-configure your ImportConfiguration they will have to implement"
Where i should put "ImportConfiguration" ?
i see import action in panel when i click i have
Call to a member function getImporter() on null
in
$importer = $this->importerFactory->getImporter($type = $import->file->getClientOriginalExtension());
I create My importerConfiguration for admin - how to connect it to admin ?
I register as service but still have error (Call to a member function getImporter() on null)
I see that my AdminContrller dont have ImporterFactory
Thanks for any info.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.