Create a New Bundle (Plugin) - Sintraconsulting/pimcore-product-sync-plugin GitHub Wiki

Install the bundle

Pimcore has extended the Symfony Bundle Creation Tool to easily Create Pimcore Bundle:

Let's say, for example, we want to create a new bundle named SintraBundle; following documentation, we have to:

  1. Open command shell
  2. cd pimcore/project/main/folder
  3. php bin/console pimcore:generate:bundle --namespace=SintraBundle

Pimcore will ask you some questions to configure your bundle: in most cases, default configuration is the best solution, so you can add the --no-interaction parmeter to avoid Pimcore to ask questions and directly proceed with bundle install.

Once you have installed the new bundle, move to folder src/SintraBundle Here, you will find basic files and folder that you need for your bundle:

  • SintraBundle.php The main file of your bundle; it must extend the AbstractPimcoreBundle class in order to work. Please Note that Pimcore follow a simple but strict name convention. If you don't follow these rules, you may have to override some default methods; check these links for more details:

Best Practices for Reusable Bundles

Extension Documentation

  • Resources folder Here you can add all configuration files for your bundle. You can find more info in Configuration Documentation

  • DependencyInjection folder Here you will find two files that allow you to load your bundle's configuration:

  1. Configuration.php implements ConfigurationInterface and override getConfigTreeBuilder() method to load root node defined in Resources/config/pimcore/routing.yml

  2. SintraExtension.php load other files in Resources/config folder for Dependency Injection. Some dependencies may be injectd by compiler. For more detalis check How to Work with Compiler Passes.

  • Controller folder Like name suggests, in this folderyou can add the controller(s) of your bundle that allow you to create your custom actions. By default, the DefaultController class extends AdminController class; you can change controller name, make the controller extends a different one and define your controller route.

Practical Controller Example:

SintraController.php

/**
 * Class SintraController
 * @package SintraBundle\Controller
 *
 * @Route("/sintra")
 */
class SintraController extends AnotherBundleController{
    //YOUR_CONTROLLER_ACTIONS...
}

Resources/config/pimcore/routing.yml

sintra:
    resource: "@SintraBundle/Controller/"
    type:     annotation
    prefix:   /admin/another-controller

Controller action will be callable on route: http://your-pimcore-url/admin/another-controller/sintra/yourActionName