Skip to content

Commit

Permalink
Add last fixes before 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbager committed Jul 15, 2018
1 parent 0b669ab commit 290d04d
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 64 deletions.
9 changes: 7 additions & 2 deletions src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
use Sylius\Component\Resource\ResourceActions;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
Expand Down Expand Up @@ -60,9 +62,12 @@ public function downloadMediaAction(Request $request): Response

$this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $media);

$response = new BinaryFileResponse($media->getOriginalPath());
$mediaPath = $this->getParameter('kernel.project_dir') . '/web' . $media->getPath();
$mediaFile = new File($mediaPath);
$mediaName = $media->getName() . '.' . $mediaFile->guessExtension();
$response = new BinaryFileResponse($mediaPath);

$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $mediaName);
$response->headers->set('Content-Type', $media->getMimeType());

return $response;
Expand Down
14 changes: 0 additions & 14 deletions src/Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,8 @@ public function setPath(?string $path): void
$this->path = $path;
}

public function getOriginalPath(): ?string
{
return $this->originalPath;
}

public function setOriginalPath(?string $originalPath): void
{
$this->originalPath = $originalPath;
}

public function getFile(): ?File
{
if (null === $this->type && null !== $this->path) {
$this->file = new File($this->path);
}

return $this->file;
}

Expand Down
4 changes: 0 additions & 4 deletions src/Entity/MediaInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function getPath(): ?string;

public function setPath(?string $path): void;

public function getOriginalPath(): ?string;

public function setOriginalPath(?string $originalPath): void;

public function getFile(): ?File;

public function setFile(?File $file): void;
Expand Down
11 changes: 6 additions & 5 deletions src/Fixture/Factory/MediaFixtureFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use BitBag\SyliusCmsPlugin\Entity\MediaTranslationInterface;
use BitBag\SyliusCmsPlugin\MediaProvider\ProviderInterface;
use BitBag\SyliusCmsPlugin\Repository\MediaRepositoryInterface;
use BitBag\SyliusCmsPlugin\Resolver\MediaProviderResolverInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\HttpFoundation\File\File;

Expand All @@ -29,8 +30,8 @@ final class MediaFixtureFactory implements FixtureFactoryInterface
/** @var FactoryInterface */
private $mediaTranslationFactory;

/** @var ProviderInterface */
private $imageProvider;
/** @var MediaProviderResolverInterface */
private $mediaProviderResolver;

/** @var MediaRepositoryInterface */
private $mediaRepository;
Expand All @@ -44,14 +45,14 @@ final class MediaFixtureFactory implements FixtureFactoryInterface
public function __construct(
FactoryInterface $mediaFactory,
FactoryInterface $mediaTranslationFactory,
ProviderInterface $imageProvider,
MediaProviderResolverInterface $mediaProviderResolver,
MediaRepositoryInterface $mediaRepository,
ProductsAssignerInterface $productsAssigner,
SectionsAssignerInterface $sectionsAssigner
) {
$this->mediaFactory = $mediaFactory;
$this->mediaTranslationFactory = $mediaTranslationFactory;
$this->imageProvider = $imageProvider;
$this->mediaProviderResolver = $mediaProviderResolver;
$this->mediaRepository = $mediaRepository;
$this->productsAssigner = $productsAssigner;
$this->sectionsAssigner = $sectionsAssigner;
Expand Down Expand Up @@ -86,7 +87,7 @@ private function createMedia(string $code, array $mediaData): void
$media->setEnabled($mediaData['enabled']);
$media->setFile(new File($mediaData['path']));

$this->imageProvider->upload($media);
$this->mediaProviderResolver->resolveProvider($media)->upload($media);

foreach ($mediaData['translations'] as $localeCode => $translation) {
/** @var MediaTranslationInterface $mediaTranslation */
Expand Down
2 changes: 1 addition & 1 deletion src/MediaProvider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ public function render(MediaInterface $media, array $options = []): string

public function upload(MediaInterface $media): void
{
$this->uploader->upload($media, $this->pathPrefix);
$this->uploader->upload($media, $this->pathPrefix);
}
}
5 changes: 0 additions & 5 deletions src/Resources/config/doctrine/Media.orm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ BitBag\SyliusCmsPlugin\Entity\Media:
type: string
length: 250
unique: true
originalPath:
column: original_path
type: string
length: 250
unique: true
mimeType:
column: mime_typ
type: string
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ services:
class: BitBag\SyliusCmsPlugin\Uploader\MediaUploader
arguments:
- "@bitbag_sylius_cms_plugin.media.filesystem"
- "%kernel.project_dir%"

bitbag_sylius_cms_plugin.media.filesystem:
class: Gaufrette\Filesystem
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/fixture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ services:
arguments:
- "@bitbag_sylius_cms_plugin.factory.media"
- "@bitbag_sylius_cms_plugin.factory.media_translation"
- "@bitbag_sylius_cms_plugin.media_provider.image"
- "@bitbag_sylius_cms_plugin.resolver.media_provider"
- "@bitbag_sylius_cms_plugin.repository.media"
- "@bitbag_sylius_cms_plugin.assigner.products"
- "@bitbag_sylius_cms_plugin.assigner.sections"
8 changes: 5 additions & 3 deletions src/Resources/views/Shop/Media/Show/file.html.twig
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{% if null != media.name %}
<h2>{{ media.name }}</h2>
<h2>{{ media.name|raw }}</h2>
{% endif %}

<a class="ui labeled icon button primary" href="{{ path('bitbag_sylius_cms_plugin_shop_media_download', {'code': media.code}) }}">
<i class="download icon"></i>
<p>{{ media.description|raw }}</p>

<a class="ui icon labeled primary button" href="{{ path('bitbag_sylius_cms_plugin_shop_media_download', {'code': media.code}) }}">
<i class="download icon"></i>
{{ 'bitbag_sylius_cms_plugin.ui.download'|trans }}
</a>
4 changes: 1 addition & 3 deletions src/Resources/views/Shop/Media/Show/image.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{% set path = '/'~media.path %}

<h2>{{ media.name|raw }}</h2>

<img class="ui fluid image" src="{{ path }}" alt="{{ media.name }}"/>
<img class="ui fluid image" src="{{ media.path }}" alt="{{ media.name }}"/>

<p>{{ media.description|raw }}</p>
8 changes: 4 additions & 4 deletions src/Resources/views/Shop/Media/Show/video.html.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% set path = '/'~media.path %}

<div>
{% if null != media.name %}
<h2>{{ media.name }}</h2>
<h2>{{ media.name|raw }}</h2>
{% endif %}

<video controls width="100%" src="{{ path }}"></video>
<video controls width="100%" src="{{ media.path }}"></video>

<p>{{ media.description|raw }}</p>
</div>
9 changes: 2 additions & 7 deletions src/Uploader/MediaUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@ final class MediaUploader implements MediaUploaderInterface
/** @var Filesystem */
private $filesystem;

/** @var string */
private $projectDir;

public function __construct(Filesystem $filesystem, string $projectDir)
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
$this->projectDir = $projectDir;
}

public function upload(MediaInterface $media, string $pathPrefix): void
Expand All @@ -51,8 +47,7 @@ public function upload(MediaInterface $media, string $pathPrefix): void
$path = $this->expandPath($hash . '.' . $file->guessExtension(), $pathPrefix);
} while ($this->filesystem->has($path));

$media->setPath($path);
$media->setOriginalPath(sprintf('%s/%s', $this->projectDir, $path));
$media->setPath('/' . $path);
$media->setMimeType($file->getMimeType());

$this->filesystem->write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
<div class="ui stackable two column grid">
<div class="column">
<div class="ui fluid segment">
{{ bitbag_cms_render_media('homepage_banner_image_1') }}
{{ bitbag_cms_render_media('homepage_video') }}
</div>
</div>
<div class="column">
<div class="ui fluid segment">
{{ bitbag_cms_render_media('homepage_banner_image_2') }}
{{ bitbag_cms_render_media('homepage_pdf') }}
</div>
</div>
</div>
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
46 changes: 34 additions & 12 deletions tests/Application/app/config/fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ sylius_fixtures:
bitbag_cms_render_block('homepage_banner_image_1')
bitbag_cms_render_block('homepage_banner_image_2')
</pre>
<p>
The block with this nice woman is linked to another page. Click her and see what happens. No pornography included. I promise <i class="em em-relieved"></i>
</p>
lorem_ipsum:
sections:
- "homepage"
Expand All @@ -112,17 +108,43 @@ sylius_fixtures:
translations:
en_US:
name: |
Some block name
homepage_banner_image_1:
type: image
path: "%fixtures_dir%/homepage_banner_1.jpeg"
<a href="/en_US/page/about">This is a linked title</a>
alt: Homepage image media
description: |
<h3>Media description</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
homepage_video:
type: video
path: "%fixtures_dir%/homepage_video.mp4"
translations:
en_US:
name: |
<a href="/en_US/page/about">Click me! <i class="em em-kiss"></i></a>
homepage_banner_image_2:
type: image
path: "%fixtures_dir%/homepage_banner_2.jpeg"
Homepage video media
alt: Homepage video
description: |
<h3>Media description</h3>
<p>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</p>
homepage_pdf:
type: file
path: "%fixtures_dir%/BitBagOffer.pdf"
translations:
en_US:
name: Homepage PDF media
alt: BitBag offer
description: |
<h3>File description</h3>
<p>
The below button links to a PDF file.
Check it out! <i class="em em-slightly-smiling-face"></i>
</p>
size_table:
type: image
path: "%fixtures_dir%/size_table.jpeg"
Expand Down

0 comments on commit 290d04d

Please sign in to comment.