Skip to the content
Documentation

Creating the bundle: comparison of v.2 vs v.3

No ratings yet

Versions Compared

Old Version 2

changes.mady.by.user André Rømcke

Saved on Dec 15, 2015

compared with

New Version Current

changes.mady.by.user Dominika Kurek

Saved on Feb 01, 2016

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Custom FieldTypes Field Types follow the Symfony 2 extension mechanism: bundles . We can get started with a bundle using the built-in Symfony 2 bundle generator.

Generating the bundle

From the eZ  Publish 5 Platform root, run the following:

Code Block
language bash
php app/console generate:bundle

First, we are asked for the namespace. As the vendor, we will use EzSystems as the root namespace. This must of course be changed to whatever identifies you as a vendor (your name, company name, etc). We then choose a preferably unique name for the field type Field Type itself, and make the name end with Bundle. I’ve chosen TweetFieldTypeBundle.

 

Code Block
language bash
Bundle namespace: EzSystems/TweetFieldTypeBundle<enter>

We must next input the bundle’s name. Nothing exotic here: we concatenate the vendor’s namespace and the bundle’s namespace, which is the default. We just hit enterEnter:

Code Block
language bash
Bundle name [EzSystemsTweetFieldTypeBundle]:<enter>

We are then asked for the target directory. We will begin within the src folder, but we could (and should!) version it and have it moved to vendor at some point. Again, this is the default, and we just hit enterEnter.

Code Block
language bash
Target directory [/home/bertrand/www/exponential5/src]:<enter>

We must then specify which format the generation configuration must be generated as. We will use yml, since it is what we use in eZ Publish 5 Platform itself. Of course, any other format could have been be used.

Code Block
language bash
Configuration format (yml, xml, php, or annotation): yml<enter>

The generator will then offer us to generate create the whole directory structure for us. Since our bundle isn’t really a standard Symfony full stack bundle, we decline.

Code Block
language bash
Do you want to generate the whole directory structure [no]? no<enter>

We then get a summary of what will be generated:

 

Code Block
language bash
You are going to generate a "EzSystems\TweetFieldTypeBundle\EzSystemsTweetFieldTypeBundle" bundle
in "/home/bertrand/www/exponential5/src/" using the "yml" format.
Do you confirm generation [yes]?<enter>

After generation, the wizard will offer us to update the kernel with our bundle (answer "yes please"), and to update the app’s routing with our bundle’s route file (answer "no thanks").

Code Block
language bash
Generating the bundle code: OK
Checking that the bundle is autoloaded: OK
Confirm automatic update of your Kernel [yes]? <enter>
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]? no <enter>

Our bundle should have been now be generated. Navigate to src/EzSystems/EzSystemsTweetBundle, and you should see this the following structure:

Code Block
$ ls -l src/EzSystems/TweetFieldTypeBundle
Controller
DependencyInjection
EzSystemsTweetFieldTypeBundle.php
Resources
Tests

 Feel free to delete the Controller folder, since we won’t use it in this tutorial. It could have been useful, had our field type Field Type required an interface of its own.

Comments

Add a comment

Comments are read by a moderator before they appear.