Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
     Glossary
   eZ Publish 4.x / legacy

 
eZ Publish (5.x)

eZ Publish 5.x | For eZ Platform & eZ Studio topics see Technical manual and User manual, for eZ Publish 4.x and Legacy topics see eZ Publish legacy

Skip to end of metadata
Go to start of metadata

The Value class of a FieldType is by design very simple. It is meant to be stateless, and as lightweight as possible. Therefore, this class must contain as little logic as possible, as this is the Type class responsibility.

The Value will at least contain:

  • public properties, used to store the actual data 

  • an implementation of the __toString() method (required by the Value interface we inherit from)

By default, the constructor from FieldType\Value will be used, and allows you to pass a hash of property / value pairs. In our example, we can see that we can override it as well if we want.

The Tweet FieldType is going to store three things:

  • The tweet’s URL

  • The tweet’s author URL

  • The body, as an HTML string 

At this point, we don’t care where those are stored. All we care about is what we want our FieldType to expose as an API. We end up with the following properties:

eZ/FieldType/Tweet/Value.php

The only thing left to honor the FieldType\Value interface is the __toString() method. Let’s say that ours will return the tweet’s URL:

eZ/FieldType/Tweet/Value.php

1 Comment

  1. Doc improvement request: it is not clear which interface should be implemented. As a matter of fact, core fieldtype values extend eZ\Publish\Core\FieldType\MapLocation\Value which is where the abstract __toString() is defined