Creating a Tweet Field Type¶
Getting the code
The code created in this tutorial is available on GitHub: (https://github.com/ezsystems/TweetFieldTypeBundle).
This tutorial covers the creation and development of a custom eZ Platform Field Type. Field Types are the smallest building blocks of content. eZ Platform comes with about 30 native types that cover most common needs (Text line, Rich text, Email, Author list, Content relation, Map location, Float, etc.)
Field Types are responsible for:
- Storing data, either using the native storage engine mechanisms or specific means
- Validating input data
- Making the data searchable (if applicable)
- Displaying Fields of this type
Custom Field Types are a very powerful type of extension, since they allow you to hook deep into the content model.
You can find the in-depth documentation about Field Types. It describes how each component of a Field Type interacts with the various layers of the system, and how to implement those.
This tutorial is aimed at developers who are familiar with eZ Platform and are comfortable with operating in PHP and Symfony.
Content of the tutorial¶
This tutorial will demonstrate how to create a Field Type on the example of a Tweet Field Type. It will:
- Accept as input the URL of a tweet (
- Fetch the tweet using the Twitter oEmbed API (https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-oembed)
- Store the tweet’s embed contents and URL
- Display the tweet's embedded version when displaying the field from a template
To start the tutorial, you need to make a clean eZ Platform installation. Follow the guide for your system from Install eZ Platform. Remember to install using the
In this tutorial you will go through the following steps:
- 1. Create the bundle
- 2. Implement the Tweet\Value class
- 3. Implement the Tweet\Type class
- 4. Register the Field Type as a service
- 5. Implement the Legacy Storage Engine Converter
- 6. Introduce a template
- 7. Allow adding and editing the Field in Back Office
- 8. Add a validation