mpalourdio/zf2-twitter-widget

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

ZF2 view helper to easily display twitter timelines widgets

0.2.0 2017-04-08 20:08 UTC

This package is not auto-updated.

Last update: 2021-10-16 00:20:59 UTC


README

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight PHP 7.0+ MIT Licensed

zf2-twitter-widget

ZF2 view helper to easily display twitter embedded timelines widgets in a ZF2 project. Based on this library : https://github.com/mpalourdio/TwitterWidgets

Requirements

PHP 7.0+ - Only Composer installation supported

Installation

Run the command below to install via Composer

composer require mpalourdio/zf2-twitter-widget

Add "ZfTwitterWidget" to your modules list in application.config.php

Usage

    1. Create a timeline widget here : https://twitter.com/settings/widgets/new
    1. In the javascript generated code, get the URL and the data-widget-id (minimum information required)
    1. Finally, in a view, use with
echo $this->tw(
        [
            'dataWidgetId' => '1245687955000', => the id must be a string (quotes), because of long integer converted to float
            'href'         => 'https://twitter.com/NickName',
            'hrefText'     => 'Here type a title'
        ],
        true/false (true is default)
    );

All the following options are handled : https://dev.twitter.com/web/embedded-timelines#options

Their PHP equivalent as array keys to use in the view helper are :

'class'           => 'A css class, by default it will be twitter-timeline',
'href'            => 'The link to the timeline',
'hrefText'        => 'A title for your timeline to display',
'dataWidgetId'    => 'Your data widget ID : must be a string (!)',
'dataTheme'       => 'ex: dark',
'dataLinkColor'   => 'ex: #cc0000',
'width'           => 300 (integer),
'height'          => 400 (integer),
'dataChrome'      => 'noheader nofooter noborders noscrollbar transparent', => a string with options separated by a single space
'dataBorderColor' => 'border color used by the widget',
'language'        => 'The widget language detected from the page, based on the HTML lang attribute of your content. You can also set the HTML lang attribute on the embed code itself.',
'dataTweetLimit'  => 20,
'dataRelated'     => 'benward,endform',
'dataAriaPolite'  => 'polite or assertive',

You can give an instance of TwitterWidgets\Options\WidgetOptions instead of an array (or any implementation of TwitterWidgets\Timeline\WidgetOptionsInterface).

$options = new TwitterWidgets\Options\WidgetOptions();
$options->setDataWidgetId('1245687955000');
$options->setHref('https://twitter.com/NickName');
$options->setHrefText('Here type a title');
echo $this->tw($options);

The view helper second parameter is a boolean (true by default), that indicates if you must render the javascript code for your widget. If you have more that one widget on your page, use the OneTimeJsViewHelper to only add once the javascript code, just before your </body>. This will avoid some overhead. See https://dev.twitter.com/web/javascript/loading

$this->inlineScript()->captureStart();
echo $this->twJS();
$this->inlineScript()->captureEnd();