Step 1 - Create the bundle¶
Tip
You can find all files used and modified in this step on GitHub.
FieldTypes, like any other eZ Platform extensions, must be provided as Symfony bundles. This chapter covers the creation and organization of this bundle.
Once you have installed eZ Platform, including the creation of a database for the tutorial, configured a server, and started the web server, you need to create a code base for the tutorial.
The Field Type will be placed in a Symfony bundle. You can get started with a bundle using the built-in Symfony bundle generator. Then you will configure the bundle to be able to write the code you need to create a Field Type.
Generate the bundle¶
From the eZ Platform root, run the following:
1 |
|
Our bundle should now be generated. Navigate to src/EzSystems/TweetFieldTypeBundle
and you should see the following structure:
1 2 3 4 5 6 |
|
Note
If the generate:bundle
command returns an error about registering the bundle namespace in composer.json
, add the following line to the composer.json
file within the psr-4
section:
1 |
|
Then execute the following command to regenerate the autoload files:
1 |
|
Feel free to delete the Controller folder, since you won’t use it in this tutorial. It could have been useful, had our Field Type required an interface of its own.
Also, you can safely delete the Resources/views/Default
folder and Resources/config/routing.yml
file, as they won't be needed. You should remove the ez_systems_tweet_field_type
entry from the app/config/routing.yml
file as well.
Structure the bundle¶
At this point, you have a basic application-specific Symfony bundle. First you will create the structure for the Field Type.
To make it easier to move around the code, you will to some extent mimic the structure that is used in the kernel of eZ Platform. Native Field Types are located inside ezpublish-kernel
(in vendor/ezsystems
), in the eZ/Publish/Core/FieldType
folder.
Each Field Type has its own subfolder: TextLine
, Email
, Url
, etc.
You will use a structure quite close to this:
From the tutorial git repository, list the contents of the eZ/Publish/FieldType
folder:
Now prepare the files for two classes you will need for the Field Type:
TweetFieldTypeBundle/eZ/Publish/FieldType/Tweet/Type.php
TweetFieldTypeBundle/eZ/Publish/FieldType/Tweet/Value.php
1 2 3 4 5 6 7 8 9 10 |
|
1 2 3 4 5 6 7 8 9 |
|