Message-ID: <33786846.3772.1485855279346.JavaMail.confluence@ip-10-127-227-164> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_3771_1243714298.1485855279346" ------=_Part_3771_1243714298.1485855279346 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html Implement the Tweet\Value class

Implement the Tweet\Value class

=20
=20
=20
=20

The Value class of a Field Type is by design very simple. It is meant to= be stateless, and as lightweight as possible. Therefore, this class must c= ontain as little logic as possible, as this is the responsibility of the Ty= pe class .

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 Field Type is going to store three things:

  • The tweet=E2=80=99s URL

  • The tweet=E2=80=99s author URL

  • The body, as an HTML string  

At this point, we don=E2=80=99t care where those are stored. All we care= about is what we want our Field Type to expose as an API. We end up with t= he following properties:

eZ/FieldType/Tweet/Value.php
=20
/**
* Tweet URL on twitter.com (http://twitter.com/UserName/status/id).
* @var string
*/
public $url;

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

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

The only thing left to honor the FieldType\Value interfac= e is the __toString() method. Let=E2=80=99s say that ours wil= l return the tweet=E2=80=99s URL:

eZ/FieldType/Tweet/Value.php
=20
public function __toString()
{
   return $this->url;
}
=20
=20
=20
=20
=20
Tutorial path
=20

=20
    =20
    =20
    =20
=20
=20 =20 = =20 =20 =20 =20 =20 =20 =20 = =20 =20 =20 =20 =20
=20 =20
=20
=20
=20

=20
=20
=20
=20
------=_Part_3771_1243714298.1485855279346--