Skip to content

Latest commit

 

History

History
138 lines (98 loc) · 5.16 KB

create-bundle.rst

File metadata and controls

138 lines (98 loc) · 5.16 KB
.. index::
    single: Bundle; Create a Bundle
    single: Customization; Create a custom Bundle

Create a Bundle

Create a Bundle Manually

First you need to specify name and namespace of your bundle. Symfony framework already has |best practices for bundle structure and bundle name| and we recommend to follow these practices and use them.

Let us assume that we want to create the AcmeDemoBundle and put it under the namespace Acme\Bundle\DemoBundle in the /src directory. We need to create the corresponding directory structure and the bundle file with the following content:

.. oro_integrity_check:: 60007b7c5dc2549192f5138c7861f5a16a193b3e

   .. literalinclude:: /code_examples/commerce/demo/AcmeDemoBundle.php
       :caption: src/Acme/Bundle/DemoBundle/AcmeDemoBundle.php
       :language: php
       :lines: 4-6, 11-14, 28

Basically, it is a regular Symfony bundle. The only difference is in the way it will be enabled (see chapter Enable a Bundle).

Create a Bundle Service Container Extension

For a load configuration files you need to create Service Container Extension. See |Symfony Configuration Files|

.. oro_integrity_check:: 04414a05c934f584d038f4791e3ccd8c4db19876

   .. literalinclude:: /code_examples/commerce/demo/DependencyInjection/AcmeDemoExtension.php
       :caption: src/Acme/Bundle/DemoBundle/DependencyInjection/AcmeDemoExtension.php
       :language: php
       :lines: 4-20, 28-29

Create basic Resources/config/services.yml for define service parameters. See |Symfony Service Parameters|

 services:

Enable a Bundle

Now you have all the required files to enable the new bundle. To enable the bundle:

  1. Create a Resources/config/oro/bundles.yml file with the following content:
.. oro_integrity_check:: dd88c5c8abe0268ea4699f1cd0adc2cb0e681774

   .. literalinclude:: /code_examples/commerce/demo/Resources/config/oro/bundles.yml
       :caption: src/Acme/Bundle/DemoBundle/Resources/config/oro/bundles.yml
       :language: yaml
       :lines: 2-3

   This file provides a list of bundles to register. All such files are automatically parsed to load the required bundles.

  1. Regenerate the application cache using console command cache:clear:

    user@host:/var/www/vhosts/platform-application$ php bin/console cache:clear
    Clearing the cache for the dev environment with debug true
    

    Note

    If you are working in production environment, use parameter --env=prod with the command.

  2. Check if your bundle is registered and active with following command:

    php bin/console debug:container --parameter=kernel.bundles --format=json | grep AcmeDemoBundle
    

    Note

    Replace grep argument with your bundle's proper name

  3. When your bundle is registered and active, the following output (or a similar one) will be displayed in the console after running the command:

    "AcmeDemoBundle": "Acme\\Bundle\\DemoBundle\\AcmeDemoBundle",
    

References