Global navigation

   Documentation Center
   eZ Studio & eZ Platform
     User Manual
     Technical Manual
   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

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


  • The Twitter\TwitterClient class:
  • The Twitter\TwitterClientInterface interface
  • An ezsystems.tweetbundle.twitter.client service that uses the class above.

The interface has one method: getEmbed( $statusUrl ) , that, given a tweet's URL, returns the embed code as a string. The implementation is very simple, for the sake of simplicity, but gets the job done. Ideally, it should at the very least handle errors, but it is not necessary here.

Injecting the twitter client into Tweet\Type

Our FieldType doesn't have a constructor yet. We will create one, with an instance of Twitter\TwitterClientInterface as the argument, and store it in a new protected property:

Code Block
use EzSystems\TweetFieldTypeBundle\Twitter\TwitterClientInterface;
class Type extends FieldType
    /** @var TwitterClientInterface */
    protected $twitterClient;

    public function __construct( TwitterClientInterface $twitterClient )
        $this->twitterClient = $twitterClient;
Completing the value using the twitter client

As described above, before creating the PersistenceValue object in toPersistenceValue, we will fetch the tweet's embed contents using the client, and assign it to Tweet\Value::$data:

Code Block
 public function toPersistenceValue( SPIValue $value )
    // if ( $value === null )
    // {...}

    if ( $value->contents === null )
        $value->contents = $this->twitterClient->getEmbed( $value->url );
    return new PersistenceValue(
    // array(...)

And that's it ! When the persistence layer stores content from our type, the value will be completed with what the twitter API returns.




  Previous: Implementing the Tweet\Value class


Next: Registering the FieldType as a service