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
9
src/AppBundle/AppBundle.php
Normal file
9
src/AppBundle/AppBundle.php
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class AppBundle extends Bundle
|
||||
{
|
||||
}
|
20
src/AppBundle/DependencyInjection/AppExtension.php
Normal file
20
src/AppBundle/DependencyInjection/AppExtension.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace AppBundle\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
|
||||
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class AppExtension extends Extension
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(array $configs, ContainerBuilder $container)
|
||||
{
|
||||
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
|
||||
$loader->load('services.yml');
|
||||
}
|
||||
}
|
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';
|
||||
}
|
||||
|
||||
}
|
9
src/AppBundle/config/services.yml
Normal file
9
src/AppBundle/config/services.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
services:
|
||||
app.twig.vimeo:
|
||||
class: AppBundle\Twig\VimeoExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
||||
app.twig.youtube:
|
||||
class: AppBundle\Twig\YouTubeExtension
|
||||
tags:
|
||||
- { name: twig.extension }
|
Loading…
Add table
Add a link
Reference in a new issue