Creating a Tweet Field Type
About this tutorial
This tutorial aims at covering the creation and development of a custom eZ Platform Field Type.
We will do this by implementing a Tweet Field Type. It will:
- Accept as input the URL of a tweet (https://twitter.com/<username>/status/<id>)
- Fetch the tweet using the Twitter oEmbed API (https://dev.twitter.com/docs/embedded-tweets)
- Store the tweet’s embed contents and URL
- Display the tweet's embedded version when displaying the field from a template
About Field Types
Field Types are the most granular building blocks for content managed by eZ Platform. The system 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 an instance of the 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 and their best practices here. It describes how each component of a Field Type interacts with the various layers of the system, and how to implement those.
Getting the code
The code created throughout this tutorial is available on GitHub: https://github.com/ezsystems/TweetFieldTypeBundle.
Steps
The bundle
Field Types, like any other eZ Platform plugin, must be provided as Symfony2 bundles. This chapter covers the creation and organization of this bundle.
Read more about creating and structuring the bundle.
API
This part covers the implementation of the eZ Platform API elements required to implement a custom Field Type.
Read more about implementing the Tweet\Value class and the Tweet\Type class.
Converter
Storing data from any Field Type into the Legacy Storage Engine requires that your custom data is mapped to the data model.
Read more about implementing the Legacy Storage Engine Converter.
Templating
Displaying a Field Type's data is done through a Twig template.
Read more about implementing the Field Type template.
PlatformUI integration
Viewing and editing values of the Field Type in PlatformUI requires that you extend PlatformUI, using mostly Javascript.
You should ideally read the general extensibility documentation for PlatformUI. The part about templating covers view templates. Edit templates are not documented at the time of writing, but Netgen has published a tutorial that covers the topic: http://www.netgenlabs.com/Blog/Adding-support-for-a-new-field-type-to-Exponential-Platform-UI.
Tutorial Path
In this section
- Build the bundle FieldTypes, like any other eZ Platform extensions, must be provided as Symfony 2 bundles. This chapter covers the creation and organization of this bundle.
- Register the Field Type as a service To complete the implementation, we must register our Field Type with Symfony by creating a service for it.
- Implement the Legacy Storage Engine Converter So far, our Field Type’s value is represented by the Tweet\Value class. It holds a semantic representation of the type’s data: a url, author url and the tweet's content.
- Introduce a template In order to display data of our Field Type from templates, we need to create and register a template for it. You can find documentation about FieldType templates, as well as on importing settings from a bundle .
- Build the bundle FieldTypes, like any other eZ Platform extensions, must be provided as Symfony 2 bundles. This chapter covers the creation and organization of this bundle.
- Build the bundle FieldTypes, like any other eZ Platform extensions, must be provided as Symfony 2 bundles. This chapter covers the creation and organization of this bundle.
Contributors
- Dominika Kurek
- David Christian Liedle Updated
Comments
Add a comment