Add AppBundle and the YouTube and Vimeo Twig functions

This commit is contained in:
Oliver Davies 2016-03-28 19:11:12 +01:00
parent 2f7d9de95b
commit 3cb4e74448
11 changed files with 134 additions and 5 deletions

View file

@ -0,0 +1,41 @@
<?php
namespace AppBundle\Twig;
use Twig_Extension;
use Twig_SimpleFunction;
class VimeoExtension extends Twig_Extension
{
public function getFunctions()
{
return [
new Twig_SimpleFunction('vimeo', [$this, 'embedCode'])
];
}
/**
* Generates the embed code for a video.
*
* @param $videoId
* The ID of the video.
*
* @return string
*/
public function embedCode($videoId)
{
return sprintf(
'<iframe src="https://player.vimeo.com/video/%s?title=0&portrait=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>',
$videoId
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'vimeo';
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace AppBundle\Twig;
use Twig_Extension;
use Twig_SimpleFunction;
class YouTubeExtension extends Twig_Extension
{
/**
* {@inheritdoc}
*/
public function getFunctions()
{
return [
new Twig_SimpleFunction('youtube', [$this, 'embedCode'])
];
}
/**
* Generates the embed code for a video.
*
* @param $videoId
* The ID of the video.
*
* @return string
*/
public function embedCode($videoId)
{
return sprintf(
'<iframe width="560" height="315" src="https://www.youtube.com/embed/%s" frameborder="0" allowfullscreen></iframe>',
$videoId
);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'youtube';
}
}