Skip to content

Commit

Permalink
Merge pull request sonata-project#918 from core23/admin-format
Browse files Browse the repository at this point in the history
Admin thumbnail format configuration
  • Loading branch information
OskarStark committed Feb 19, 2016
2 parents 972ef88 + b89159a commit f0e6752
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
10 changes: 3 additions & 7 deletions DependencyInjection/Compiler/AddProviderCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@ public function process(ContainerBuilder $container)
$this->attachArguments($container, $settings);
$this->attachProviders($container);

$format = $container->getParameter('sonata.media.admin_format');

foreach ($container->findTaggedServiceIds('sonata.media.provider') as $id => $attributes) {
$container->getDefinition($id)->addMethodCall('addFormat', array('admin', array(
'quality' => 90,
'width' => 200,
'format' => 'jpg',
'height' => false,
'constraint' => true,
)));
$container->getDefinition($id)->addMethodCall('addFormat', array('admin', $format));
}
}

Expand Down
11 changes: 11 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ public function getConfigTreeBuilder()
->children()
->scalarNode('db_driver')->isRequired()->end()
->scalarNode('default_context')->isRequired()->end()
->arrayNode('admin_format')
->info('Configures the thumbnail preview for the admin')
->addDefaultsIfNotSet()
->children()
->scalarNode('width')->defaultValue(200)->end()
->scalarNode('height')->defaultValue(false)->end()
->scalarNode('quality')->defaultValue(90)->end()
->scalarNode('format')->defaultValue('jpg')->end()
->scalarNode('constraint')->defaultValue(true)->end()
->end()
->end()
->end()
;

Expand Down
2 changes: 2 additions & 0 deletions DependencyInjection/SonataMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public function load(array $configs, ContainerBuilder $container)
$pool->addMethodCall('addContext', array($name, $settings['providers'], $formats, $settings['download']));
}

$container->setParameter('sonata.media.admin_format', $config['admin_format']);

$strategies = array_unique($strategies);

foreach ($strategies as $strategyId) {
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/reference/advanced_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Full configuration options:
category: Application\Sonata\ClassificationBundle\Entity\Category
default_context: default
admin_format: { width: 200 , quality: 90, format: 'jpg'}
contexts:
default: # the default context is mandatory
download:
Expand Down
37 changes: 37 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Sonata\MediaBundle\Tests;

use Sonata\MediaBundle\DependencyInjection\Configuration;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
public function testAdminFormat()
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array(
array(
'db_driver' => 'foo',
'default_context' => 'default',
),
));

$this->assertNotNull($config['admin_format']);
$this->assertSame(200, $config['admin_format']['width']);
$this->assertSame(false, $config['admin_format']['height']);
$this->assertSame(90, $config['admin_format']['quality']);
$this->assertSame('jpg', $config['admin_format']['format']);
$this->assertSame(true, $config['admin_format']['constraint']);
}
}

0 comments on commit f0e6752

Please sign in to comment.