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:

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:

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:

/**
* Tweet URL on twitter.com (http://twitter.com/UserName/status/id).
* @var string
*/
public $url;

 
/**
* Author's tweet URL (http://twitter.com/UserName)
* @var string
*/
public $authorUrl;

 
/**
* The tweet's embed HTML
* @var string
*/
public $contents;

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:

public function __toString()
{
   return $this->url;
}

 


 

  Previous: The bundle

Next: Implementing the Tweet\Type class