Add AppBundle and the YouTube and Vimeo Twig functions
This commit is contained in:
parent
2f7d9de95b
commit
3cb4e74448
11 changed files with 134 additions and 5 deletions
41
src/AppBundle/Twig/VimeoExtension.php
Normal file
41
src/AppBundle/Twig/VimeoExtension.php
Normal 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';
|
||||
}
|
||||
|
||||
}
|
44
src/AppBundle/Twig/YouTubeExtension.php
Normal file
44
src/AppBundle/Twig/YouTubeExtension.php
Normal 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';
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue