Skip to content

Commit

Permalink
REMOVE - LiipImagineBundle dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelBrauner committed Dec 11, 2023
1 parent bd5d10a commit 7a87ca9
Show file tree
Hide file tree
Showing 12 changed files with 16 additions and 78 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"nyholm/symfony-bundle-test": "1.8.1",
"doctrine/doctrine-bundle": "^2.5",
"symplify/amnesia": "^10.2",
"liip/imagine-bundle": "^2.7",
"symfony/twig-bundle": "^4.4|^5.0|^6.0",
"symfony/panther": "^2.0",
"dbrekelmans/bdi": "^1.0",
Expand Down
21 changes: 0 additions & 21 deletions config/filter_sets.php

This file was deleted.

8 changes: 2 additions & 6 deletions src/DependencyInjection/MediaBundleExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MediaBundleExtension extends Extension implements PrependExtensionInterfac
* @inheritDoc
* @throws \Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$phpFileLoader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$phpFileLoader->load('services.php');
Expand All @@ -24,16 +24,12 @@ public function load(array $configs, ContainerBuilder $container)
/**
* @throws \Exception
*/
public function prepend(ContainerBuilder $container)
public function prepend(ContainerBuilder $container): void
{
$phpFileLoader = new PhpFileLoader($container, new FileLocator(__DIR__ . '/../../config'));

if ($container->hasExtension('twig')) {
$phpFileLoader->load('form_theme.php');
}

if ($container->hasExtension('liip_imagine')) {
$phpFileLoader->load('filter_sets.php');
}
}
}
12 changes: 8 additions & 4 deletions src/Form/Type/ImageType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ImageType extends AbstractType
{
const IMAGE_ENTITY_NAME = 'App\Entity\Media\Image';

public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('file', FileType::class, $options['file_options']);
}
Expand All @@ -26,17 +26,21 @@ public function configureOptions(OptionsResolver $resolver): void
}

$resolver->define('placeholder_image_path')
->allowedTypes('string')
->allowedTypes('string', 'bool')
->allowedValues(static function ($value) {
return $value === false || is_string($value);
})
->default('bundles/media/images/image-placeholder.jpg')
->info('The public path to the placeholder image for this image field.');
->info('The public path to the placeholder image for this image field. It will be used if no image is uploaded. If you want to disable the placeholder image, set this option to false.');


$resolver->define('file_options')
->allowedTypes('array')
->default([])
->info('The array of options for the file field.');
}

public function finishView(FormView $view, FormInterface $form, array $options)
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$view->vars = array_replace($view->vars, ['row_attr' => Arr::attachClass($view->vars['row_attr'], 'cp--form--single_image')]);

Expand Down
5 changes: 2 additions & 3 deletions src/Resources/assets/controllers/image_upload_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ export default class extends Controller {
static targets = []

connect() {
this.element.querySelector('input[type=file]').addEventListener('change', (input) => {
this.displayUploadedImage(input);
})
this.element.querySelector('input[type=file]')
.addEventListener('change', input => this.displayUploadedImage(input))
}

displayUploadedImage(input) {
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/views/form/image_theme.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
{% block image_preview %}
<div class="image-preview">
{% if form.vars.value.fullPath|default(null) is not null %}
<img src="{{ form.vars.value.fullPath|imagine_filter('form_preview') }}"
<img src="{{ form.vars.value.fullPath }}"
alt="{{ form.vars.value.altText ?? form.vars.value.fileName }}"/>
{% else %}
{% elseif placeholder_image_path != false %}
<img src="{{ asset(placeholder_image_path) }}" alt="avatar"/>
{% endif %}
</div>
Expand Down
1 change: 0 additions & 1 deletion tests/app/config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Braunstetter\MediaBundle\MediaBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['all' => true]
];
8 changes: 0 additions & 8 deletions tests/app/config/packages/liip_imagine.yaml

This file was deleted.

5 changes: 1 addition & 4 deletions tests/app/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,4 @@ test_existing_image:

test_two_existing_images:
path: /test-two-existing-images
controller: App\Controller\TestController::testWithTwoExistingImages

liip_imagine:
resource: '@LiipImagineBundle/Resources/config/routing.yaml'
controller: App\Controller\TestController::testWithTwoExistingImages
1 change: 0 additions & 1 deletion tests/app/src/MediaBundleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct(private array $configs = [])
private function configureContainer(ContainerConfigurator $container): void
{
$container->import(__DIR__ . '/../config/config.php');
$container->import(__DIR__ . '/../config/packages/liip_imagine.yaml');

$container->extension('twig', [
'paths' => [
Expand Down
26 changes: 0 additions & 26 deletions tests/tests/BundleExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
use Braunstetter\MediaBundle\DependencyInjection\MediaBundleExtension;
use Braunstetter\MediaBundle\Entity\EventListeners\FileDeleteListener;
use Braunstetter\MediaBundle\Uploader\FilesystemUploader;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\ChainLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FileSystemLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\FlysystemLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\StreamLoaderFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\AwsS3ResolverFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\FlysystemResolverFactory;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\WebPathResolverFactory;
use Liip\ImagineBundle\DependencyInjection\LiipImagineExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
use Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -32,7 +24,6 @@ protected function getContainerExtensions(): array
return [
new MediaBundleExtension(),
new TwigExtension(),
$this->getLiipImagineExtension(),
];
}

Expand All @@ -46,9 +37,6 @@ public function test_services_are_getting_loaded()
$twigExtension = $this->container->getExtension('twig');
$this->assertInstanceOf(TwigExtension::class, $twigExtension);
$this->assertTrue($this->formThemeExists($twigExtension, 'form_div_layout.html.twig'));

$liipExtension = $this->container->getExtension('liip_imagine');
$this->assertInstanceOf(LiipImagineExtension::class, $liipExtension);
}

private function getConfig(Extension $extension, string $name)
Expand All @@ -67,18 +55,4 @@ private function formThemeExists(TwigExtension $twigExtension, string $name): bo
{
return in_array($name, $this->getConfig($twigExtension, 'form_themes'));
}

private function getLiipImagineExtension(): LiipImagineExtension
{
$extension = new LiipImagineExtension();
$extension->addResolverFactory(new WebPathResolverFactory());
$extension->addResolverFactory(new AwsS3ResolverFactory());
$extension->addResolverFactory(new FlysystemResolverFactory());

$extension->addLoaderFactory(new StreamLoaderFactory());
$extension->addLoaderFactory(new FileSystemLoaderFactory());
$extension->addLoaderFactory(new FlysystemLoaderFactory());
$extension->addLoaderFactory(new ChainLoaderFactory());
return $extension;
}
}
2 changes: 1 addition & 1 deletion tests/tests/Functional/Ui/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_image_preview_with_existing_image()
$this->assertTrue($client->getResponse()->isSuccessful());

$this->assertStringStartsWith(
'http://localhost',
'/tests/images/person',
$client->getCrawler()->filter('.image-preview > img')->attr('src') ?? ''
);
}
Expand Down

0 comments on commit 7a87ca9

Please sign in to comment.