定制 kunicmarko/sonata-importer-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kunicmarko/sonata-importer-bundle

最新稳定版本:0.1.3

Composer 安装命令:

composer require kunicmarko/sonata-importer-bundle

包简介

Easier handling of Import in Sonata Admin.

README 文档

README

Easier handling of Import in Sonata Admin.

Built on top of Importer.

PHP Version Latest Stable Version Latest Unstable Version

Build Status Coverage Status

Import Action

Import Form

Documentation

Installation

Because Symfony Flex auto-detects and then registers bundles on its own, you first need to install kunicmarko/importer, add it to bundles.php, and then do the same thing for kunicmarko/sonata-importer-bundle.

1. Install kunicmarko/importer

First you need to install kunicmarko/importer, and register the bundle by following this guide.

2. Add dependency with composer

composer require kunicmarko/sonata-importer-bundle

3. Register the bundle in your Kernel

return [
    //...
    KunicMarko\SonataImporterBundle\SonataImporterBundle::class => ['all' => true],
];

Configuration

Currently, you can only change the template files used in bundle, default config looks like:

# config/packages/sonata_importer.yaml
sonata_importer:
    templates:
        form:                 '@SonataImporter/form.html.twig'
        action_button:        '@SonataImporter/action_button.html.twig'
        dashboard_action:     '@SonataImporter/dashboard_action.html.twig'

How to use

If you haven't already go and read Importer documentation. I will assume you are already familiar with ImportConfiguration and I will just explain what is different in this bundle.

Prepare Admin Class

Your Admin class has to implement KunicMarko\SonataImporterBundle\Admin\AdminWithImport.

Prepare Controller

By default if you don't set Controller in your Admin service definition we will replace it with instance of KunicMarko\SonataImporterBundle\Controller\ImportCRUDController.

Custom Controller

If you are using your own custom controller make sure it implements KunicMarko\SonataImporterBundle\Controller\ControllerWithImport, also you will have to add KunicMarko\SonataImporterBundle\Controller\ImportActionTrait trait to your controller.

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.

That will look like:

class CategoryCSVImportConfiguration implements SonataImportConfiguration
{
    /**
     * @var EntityManagerInterface
     */
    private $entityManager;

    public function __construct(EntityManagerInterface $entityManager)
    {
        $this->entityManager = $entityManager;
    }

    public static function adminClass(): string
    {
        return CategoryAdmin::class;
    }

    public static function format(): string
    {
        return 'csv';
    }

    public function map(array $item, array $additionalData)
    {
        $category = new Category();

        $category->setName($item[0]);

        $this->entityManager->persist($category);
    }

    public function save(array $items, array $additionalData): void
    {
        $this->entityManager->flush();
    }
}

统计信息

  • 总下载量: 9.68k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-07-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固