Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Sep 2, 2019
2 parents 35a26bf + 063238b commit 9978ce6
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Command/AddMassMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function insertMedia(array $data, OutputInterface $output): void
$media = $this->getMediaManager()->create();

foreach ($this->setters as $pos => $name) {
\call_user_func([$media, 'set'.$name], $data[$pos]);
$media->{'set'.$name}($data[$pos]);
}

try {
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Block/block_feature_media.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ file that was distributed with this source code.
<div class="sonata-media-block-feature-media-container {{ settings.class }}">

<div class="sonata-media-block-feature-media-container-{{ settings.orientation }}">
{% if media and settings.format%}
{% if media and settings.format %}
{% media media, settings.format %}
{% else %}
{# no media selected or format defined... #}
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/views/Extra/pixlr_editor.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ file that was distributed with this source code.
<section class="content">
<div class="row header">
<div class="col-sm-12">
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/pixlr.png')}}" alt="Pixlr"/>
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/pixlr.png') }}" alt="Pixlr"/>
</div>
</div>

Expand All @@ -74,13 +74,13 @@ file that was distributed with this source code.
<div class="row">
<div class="col-sm-6">
<a href="{{ url('sonata_media_pixlr_edit', {'id': media|sonata_urlsafeid , 'mode': 'express'}) }}" class="pixlr-box">
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/express_128.png')}}" alt="Pixlr Express"/>
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/express_128.png') }}" alt="Pixlr Express"/>
{{ "label.pixlr_express_editor"|trans({}, "SonataMediaBundle")|raw }}
</a>
</div>
<div class="col-sm-6">
<a href="{{ url('sonata_media_pixlr_edit', {'id': media|sonata_urlsafeid , 'mode': 'editor'}) }}" class="pixlr-box">
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/editor_128.png')}}" alt="Pixlr Editor"/>
<img src="{{ asset('bundles/sonatamedia/extra/pixlr/editor_128.png') }}" alt="Pixlr Editor"/>
{{ "label.pixlr_advanced_editor"|trans({}, "SonataMediaBundle")|raw }}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/Media/view.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ file that was distributed with this source code.
<li>Content Type : {{ media.contenttype }}</li>
<li>Copyright : {{ media.copyright }}</li>
<li>Author name : {{ media.authorname }}</li>
<li>CDN : {% if media.cdnisflushable %}to be flushed{% else %} last flush at {{ media.cdnflushat|date}} {% endif %}</li>
<li>CDN : {% if media.cdnisflushable %}to be flushed{% else %} last flush at {{ media.cdnflushat|date }} {% endif %}</li>
</ul>

<h2>Formats</h2>
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/MediaAdmin/edit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ file that was distributed with this source code.
</div>

{% if sonata_media.pixlr and sonata_media.pixlr.isEditable(object) %}
<div class="modal fade" id="pixlr-modal" tabindex="-1" role="dialog" aria-labelledby="{{ "label.edit_with_pixlr"|trans({}, "SonataMediaBundle")}}" aria-hidden="true">
<div class="modal fade" id="pixlr-modal" tabindex="-1" role="dialog" aria-labelledby="{{ "label.edit_with_pixlr"|trans({}, "SonataMediaBundle") }}" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">{{ "label.edit_with_pixlr"|trans({}, "SonataMediaBundle")}}</h4>
<h4 class="modal-title" id="myModalLabel">{{ "label.edit_with_pixlr"|trans({}, "SonataMediaBundle") }}</h4>
</div>
<div class="modal-body" id="pixlr-modal-body">
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/MediaAdmin/list_image.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ file that was distributed with this source code.

{% extends '@SonataAdmin/CRUD/base_list_field.html.twig' %}

{% block field%}
{% block field %}
<a href="{{ admin.generateUrl('edit', {'id' : object|sonata_urlsafeid }) }}">{% thumbnail attribute(object, field_description.name ), 'admin' with {'width': 75, 'height': 60} %}</a>
{% endblock %}
2 changes: 1 addition & 1 deletion src/Resources/views/Provider/thumbnail.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ file that was distributed with this source code.
#}

<img {% for name, value in options %}{{name}}="{{value}}" {% endfor %} />
<img {% for name, value in options %}{{ name }}="{{ value }}" {% endfor %} />
6 changes: 3 additions & 3 deletions src/Resources/views/Provider/view_youtube.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ file that was distributed with this source code.
<param name="movie" value="//www.youtube.com/v/{{ media.providerreference }}?{{ options.player_url_parameters }}"></param>
<param name="allowFullScreen" value="{{ allowFullScreen }}"></param>
<param name="allowscriptaccess" value="{{ options.player_parameters.allowScriptAccess }}"></param>
<param name="wmode" value="{{ options.player_parameters.wmode}}">
<param name="wmode" value="{{ options.player_parameters.wmode }}">

<embed
src="//www.youtube.com/v/{{ media.providerreference }}?{{ options.player_url_parameters }}"
Expand All @@ -30,7 +30,7 @@ file that was distributed with this source code.
allowfullscreen="{{ allowFullScreen }}"
width="{{ options.player_parameters.width }}"
height="{{ options.player_parameters.height }}"
wmode="{{options.player_parameters.wmode}}">
wmode="{{ options.player_parameters.wmode }}">
</embed>
</object>
{% endif %}
{% endif %}
13 changes: 8 additions & 5 deletions src/Twig/Extension/MediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
use Sonata\MediaBundle\Twig\TokenParser\MediaTokenParser;
use Sonata\MediaBundle\Twig\TokenParser\PathTokenParser;
use Sonata\MediaBundle\Twig\TokenParser\ThumbnailTokenParser;
use Twig\Environment;
use Twig\Extension\AbstractExtension;
use Twig\Extension\InitRuntimeInterface;

class MediaExtension extends \Twig_Extension implements \Twig_Extension_InitRuntimeInterface
class MediaExtension extends AbstractExtension implements InitRuntimeInterface
{
/**
* @var Pool
Expand All @@ -38,7 +41,7 @@ class MediaExtension extends \Twig_Extension implements \Twig_Extension_InitRunt
protected $mediaManager;

/**
* @var \Twig_Environment
* @var Environment
*/
protected $environment;

Expand All @@ -54,9 +57,9 @@ public function __construct(Pool $mediaService, ManagerInterface $mediaManager)
public function getTokenParsers()
{
return [
new MediaTokenParser(\get_called_class()),
new ThumbnailTokenParser(\get_called_class()),
new PathTokenParser(\get_called_class()),
new MediaTokenParser(static::class),
new ThumbnailTokenParser(static::class),
new PathTokenParser(static::class),
];
}

Expand Down
7 changes: 5 additions & 2 deletions src/Twig/Node/MediaNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

namespace Sonata\MediaBundle\Twig\Node;

class MediaNode extends \Twig_Node
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Node;

class MediaNode extends Node
{
/**
* @var string
Expand All @@ -25,7 +28,7 @@ class MediaNode extends \Twig_Node
* @param int $lineno
* @param string $tag
*/
public function __construct($extensionName, \Twig_Node_Expression $media, \Twig_Node_Expression $format, \Twig_Node_Expression $attributes, $lineno, $tag = null)
public function __construct($extensionName, AbstractExpression $media, AbstractExpression $format, AbstractExpression $attributes, $lineno, $tag = null)
{
$this->extensionName = $extensionName;

Expand Down
7 changes: 5 additions & 2 deletions src/Twig/Node/PathNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

namespace Sonata\MediaBundle\Twig\Node;

class PathNode extends \Twig_Node
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Node;

class PathNode extends Node
{
/**
* @var string
Expand All @@ -25,7 +28,7 @@ class PathNode extends \Twig_Node
* @param int $lineno
* @param string $tag
*/
public function __construct($extensionName, \Twig_Node_Expression $media, \Twig_Node_Expression $format, $lineno, $tag = null)
public function __construct($extensionName, AbstractExpression $media, AbstractExpression $format, $lineno, $tag = null)
{
$this->extensionName = $extensionName;

Expand Down
7 changes: 5 additions & 2 deletions src/Twig/Node/ThumbnailNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@

namespace Sonata\MediaBundle\Twig\Node;

class ThumbnailNode extends \Twig_Node
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Node;

class ThumbnailNode extends Node
{
/**
* @var string
Expand All @@ -25,7 +28,7 @@ class ThumbnailNode extends \Twig_Node
* @param int $lineno
* @param string $tag
*/
public function __construct($extensionName, \Twig_Node_Expression $media, \Twig_Node_Expression $format, \Twig_Node_Expression $attributes, $lineno, $tag = null)
public function __construct($extensionName, AbstractExpression $media, AbstractExpression $format, AbstractExpression $attributes, $lineno, $tag = null)
{
$this->extensionName = $extensionName;

Expand Down
11 changes: 7 additions & 4 deletions src/Twig/TokenParser/MediaTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
namespace Sonata\MediaBundle\Twig\TokenParser;

use Sonata\MediaBundle\Twig\Node\MediaNode;
use Twig\Node\Expression\ArrayExpression;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;

class MediaTokenParser extends \Twig_TokenParser
class MediaTokenParser extends AbstractTokenParser
{
/**
* @var string
Expand All @@ -42,15 +45,15 @@ public function parse(\Twig_Token $token)
$format = $this->parser->getExpressionParser()->parseExpression();

// attributes
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();

$attributes = $this->parser->getExpressionParser()->parseExpression();
} else {
$attributes = new \Twig_Node_Expression_Array([], $token->getLine());
$attributes = new ArrayExpression([], $token->getLine());
}

$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new MediaNode($this->extensionName, $media, $format, $attributes, $token->getLine(), $this->getTag());
}
Expand Down
6 changes: 4 additions & 2 deletions src/Twig/TokenParser/PathTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
namespace Sonata\MediaBundle\Twig\TokenParser;

use Sonata\MediaBundle\Twig\Node\PathNode;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;

class PathTokenParser extends \Twig_TokenParser
class PathTokenParser extends AbstractTokenParser
{
/**
* @var string
Expand All @@ -41,7 +43,7 @@ public function parse(\Twig_Token $token)

$format = $this->parser->getExpressionParser()->parseExpression();

$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new PathNode($this->extensionName, $media, $format, $token->getLine(), $this->getTag());
}
Expand Down
11 changes: 7 additions & 4 deletions src/Twig/TokenParser/ThumbnailTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
namespace Sonata\MediaBundle\Twig\TokenParser;

use Sonata\MediaBundle\Twig\Node\ThumbnailNode;
use Twig\Node\Expression\ArrayExpression;
use Twig\Token;
use Twig\TokenParser\AbstractTokenParser;

class ThumbnailTokenParser extends \Twig_TokenParser
class ThumbnailTokenParser extends AbstractTokenParser
{
/**
* @var string
Expand All @@ -42,15 +45,15 @@ public function parse(\Twig_Token $token)
$format = $this->parser->getExpressionParser()->parseExpression();

// attributes
if ($this->parser->getStream()->test(\Twig_Token::NAME_TYPE, 'with')) {
if ($this->parser->getStream()->test(Token::NAME_TYPE, 'with')) {
$this->parser->getStream()->next();

$attributes = $this->parser->getExpressionParser()->parseExpression();
} else {
$attributes = new \Twig_Node_Expression_Array([], $token->getLine());
$attributes = new ArrayExpression([], $token->getLine());
}

$this->parser->getStream()->expect(\Twig_Token::BLOCK_END_TYPE);
$this->parser->getStream()->expect(Token::BLOCK_END_TYPE);

return new ThumbnailNode($this->extensionName, $media, $format, $attributes, $token->getLine(), $this->getTag());
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Controller/GalleryAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;

class GalleryAdminControllerTest extends TestCase
{
Expand Down Expand Up @@ -130,7 +131,7 @@ private function configureSetCsrfToken(string $intention): void

private function configureSetFormTheme(FormView $formView, array $formTheme): void
{
$twig = $this->prophesize(\Twig_Environment::class);
$twig = $this->prophesize(Environment::class);

// Remove this trick when bumping Symfony requirement to 3.4+
if (method_exists(DebugCommand::class, 'getLoaderPaths')) {
Expand Down
6 changes: 4 additions & 2 deletions tests/Controller/MediaAdminControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Csrf\CsrfToken;
use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Twig\Environment;
use Twig\Error\RuntimeError;

class MediaAdminControllerTest extends TestCase
{
Expand Down Expand Up @@ -194,7 +196,7 @@ private function configureGetCurrentRequest(Request $request): void

private function configureSetFormTheme(FormView $formView, $formTheme): void
{
$twig = $this->prophesize(\Twig_Environment::class);
$twig = $this->prophesize(Environment::class);

// Remove this trick when bumping Symfony requirement to 3.4+
if (method_exists(DebugCommand::class, 'getLoaderPaths')) {
Expand All @@ -215,7 +217,7 @@ private function configureSetFormTheme(FormView $formView, $formTheme): void
$formExtension->renderer = $twigRenderer->reveal();

// This Throw is for the CRUDController::setFormTheme()
$twig->getRuntime($rendererClass)->willThrow(\Twig_Error_Runtime::class);
$twig->getRuntime($rendererClass)->willThrow(RuntimeError::class);
$twig->getExtension(FormExtension::class)->willReturn($formExtension->reveal());
}
$twigRenderer->setTheme($formView, $formTheme)->shouldBeCalled();
Expand Down
10 changes: 6 additions & 4 deletions tests/Twig/Extension/MediaExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
use Sonata\MediaBundle\Provider\MediaProviderInterface;
use Sonata\MediaBundle\Provider\Pool;
use Sonata\MediaBundle\Twig\Extension\MediaExtension;
use Twig\Environment;
use Twig\Template;

/**
* @author Geza Buza <bghome@gmail.com>
Expand All @@ -30,12 +32,12 @@ class MediaExtensionTest extends TestCase
private $provider;

/**
* @var Twig_Template
* @var Template
*/
private $template;

/**
* @var Twig_Environment
* @var Environment
*/
private $environment;

Expand Down Expand Up @@ -107,7 +109,7 @@ public function getProvider()
public function getTemplate()
{
if (null === $this->template) {
$this->template = $this->getMockBuilder('Twig_Template')
$this->template = $this->getMockBuilder(Template::class)
->disableOriginalConstructor()
->setMethods(['render'])
->getMockForAbstractClass();
Expand All @@ -119,7 +121,7 @@ public function getTemplate()
public function getEnvironment()
{
if (null === $this->environment) {
$this->environment = $this->getMockBuilder('Twig_Environment')
$this->environment = $this->getMockBuilder(Environment::class)
->disableOriginalConstructor()
->getMock();
$this->environment->method('loadTemplate')->willReturn($this->getTemplate());
Expand Down

0 comments on commit 9978ce6

Please sign in to comment.