Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refacto media twig functions #168

Merged
merged 3 commits into from Mar 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -8,12 +8,16 @@ sudo: false
cache:
directories:
- ~/.composer/cache
- ~/composer

before_install:
- phpenv config-add .travis.php.ini
- if [ -f ~/composer/composer.phar ]; then mv ~/composer/composer.phar ./; else wget https://getcomposer.org/composer.phar; fi
- mkdir -p ~/composer
- cp composer.phar ~/composer/composer.phar

install:
- composer install --no-progress --prefer-dist
- php -d memory_limit=-1 ./composer.phar install --no-progress --prefer-dist

script: ./bin/phpunit

Expand Down
71 changes: 56 additions & 15 deletions Media/Twig/DisplayMediaExtension.php
Expand Up @@ -42,33 +42,74 @@ public function __construct(
public function getFunctions()
{
return array(
new \Twig_SimpleFunction('display_media', array($this, 'displayMedia'), array('is_safe' => array('html'))),
new \Twig_SimpleFunction('media_preview', array($this, 'mediaPreview')),
new \Twig_SimpleFunction('get_media_format_url', array($this, 'getMediaFormatUrl')),
new \Twig_SimpleFunction('get_media_format_url_from_string', array($this, 'getMediaFormatUrlFromString')),
new \Twig_SimpleFunction('get_media_alt', array($this, 'getMediaAlt')),
new \Twig_SimpleFunction('get_media_alt_from_string', array($this, 'getMediaAltFromString')),
new \Twig_SimpleFunction('get_media_title', array($this, 'getMediaTitle')),
// Render a media or an alternative, using the display strategies
new \Twig_SimpleFunction(
'display_media',
array($this, 'displayMedia'),
array('is_safe' => array('html'))
),
// Get the url of a media or an alternative
new \Twig_SimpleFunction(
'get_media_url',
array($this, 'getMediaUrl')
),
// Get the title of a media
new \Twig_SimpleFunction(
'get_media_title',
array($this, 'getMediaTitle')
),
// Get the alt of a media
new \Twig_SimpleFunction(
'get_media_alt',
array($this, 'getMediaAlt')
),

// Get the url of a media or an alternative stored as 'id-format-format'
new \Twig_SimpleFunction(
'get_media_format_url_from_string',
array($this, 'getMediaFormatUrlFromString')
),
// Get the alt of a media stored as 'id-format-format'
new \Twig_SimpleFunction(
'get_media_alt_from_string',
array($this, 'getMediaAltFromString')
),

// DEPRECATED, NO MORE TO USE
new \Twig_SimpleFunction(
'media_preview',
array($this, 'mediaPreview'),
array('deprecated' => true)
),
// DEPRECATED, NO MORE TO USE
new \Twig_SimpleFunction(
'get_media_format_url',
array($this, 'getMediaUrl'),
array('deprecated' => true)
),
);
}

/**
* @param String $mediaId
* @param string $mediaId
* @param string $format
*
* @return String
* @return string
*/
public function displayMedia($mediaId)
public function displayMedia($mediaId, $format = '')
{
$media = $this->getMedia($mediaId);

if ($media) {
return $this->displayMediaManager->displayMedia($media);
return $this->displayMediaManager->displayMedia($media, $format);
}

return '';
}

/**
* @deprecated will be removed in 1.2.0
*
* @param String $mediaId
*
* @return String
Expand All @@ -85,12 +126,12 @@ public function mediaPreview($mediaId)
}

/**
* @param String $mediaId
* @param String $format
* @param string $mediaId
* @param string $format
*
* @return String
* @return string
*/
public function getMediaFormatUrl($mediaId, $format)
public function getMediaUrl($mediaId, $format)
{
$media = $this->getMedia($mediaId);

Expand Down