-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
256 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on mikolaj.krol@bitbag.pl. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Importer; | ||
|
||
use BitBag\SyliusCmsPlugin\Entity\MediaInterface; | ||
use BitBag\SyliusCmsPlugin\Resolver\ImporterProductsResolverInterface; | ||
use BitBag\SyliusCmsPlugin\Resolver\ImporterSectionsResolverInterface; | ||
use BitBag\SyliusCmsPlugin\Resolver\ResourceResolverInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sylius\Component\Locale\Context\LocaleContextInterface; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class MediaImporter extends AbstractImporter implements MediaImporterInterface | ||
{ | ||
/** @var ResourceResolverInterface */ | ||
private $mediaResourceResolver; | ||
|
||
/** @var LocaleContextInterface */ | ||
private $localeContext; | ||
|
||
/** @var ImporterSectionsResolverInterface */ | ||
private $importerSectionsResolver; | ||
|
||
/** @var ImporterProductsResolverInterface */ | ||
private $importerProductsResolver; | ||
|
||
/** @var EntityManagerInterface */ | ||
private $entityManager; | ||
|
||
public function __construct( | ||
ResourceResolverInterface $mediaResourceResolver, | ||
LocaleContextInterface $localeContext, | ||
ImporterSectionsResolverInterface $importerSectionsResolver, | ||
ImporterProductsResolverInterface $importerProductsResolver, | ||
EntityManagerInterface $entityManager | ||
) { | ||
$this->mediaResourceResolver = $mediaResourceResolver; | ||
$this->localeContext = $localeContext; | ||
$this->importerSectionsResolver = $importerSectionsResolver; | ||
$this->importerProductsResolver = $importerProductsResolver; | ||
$this->entityManager = $entityManager; | ||
} | ||
|
||
public function import(array $row): void | ||
{ | ||
/** @var string $code */ | ||
$code = $this->getColumnValue(self::CODE_COLUMN, $row); | ||
Assert::notNull($code); | ||
/** @var MediaInterface $media */ | ||
$media = $this->mediaResourceResolver->getResource($code); | ||
|
||
$media->setCode($code); | ||
$media->setFallbackLocale($this->localeContext->getLocaleCode()); | ||
|
||
foreach ($this->getAvailableLocales($this->getTranslatableColumns(), array_keys($row)) as $locale) { | ||
$media->setCurrentLocale($locale); | ||
$media->setName($this->getTranslatableColumnValue(self::NAME_COLUMN, $locale, $row)); | ||
$media->setDescription($this->getTranslatableColumnValue(self::DESCRIPTION_COLUMN, $locale, $row)); | ||
$media->setAlt($this->getTranslatableColumnValue(self::ALT_COLUMN, $locale, $row)); | ||
} | ||
|
||
$this->importerSectionsResolver->resolve($media, $this->getColumnValue(self::SECTIONS_COLUMN, $row)); | ||
$this->importerProductsResolver->resolve($media, $this->getColumnValue(self::PRODUCTS_COLUMN, $row)); | ||
|
||
$media->getId() ?: $this->entityManager->persist($media); | ||
$this->entityManager->flush(); | ||
} | ||
|
||
public function getResourceCode(): string | ||
{ | ||
return 'media'; | ||
} | ||
|
||
private function getTranslatableColumns(): array | ||
{ | ||
return [ | ||
self::NAME_COLUMN, | ||
self::DESCRIPTION_COLUMN, | ||
self::ALT_COLUMN, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/* | ||
* This file has been created by developers from BitBag. | ||
* Feel free to contact us once you face any issues or want to start | ||
* another great project. | ||
* You can find more information about us on https://bitbag.shop and write us | ||
* an email on mikolaj.krol@bitbag.pl. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BitBag\SyliusCmsPlugin\Importer; | ||
|
||
interface MediaImporterInterface extends ImporterInterface | ||
{ | ||
const CODE_COLUMN = 'code'; | ||
const SECTIONS_COLUMN = 'sections'; | ||
const CHANNELS_COLUMN = 'channels'; | ||
const PRODUCTS_COLUMN = 'products'; | ||
const NAME_COLUMN = 'name__locale__'; | ||
const DESCRIPTION_COLUMN = 'description__locale__'; | ||
const ALT_COLUMN = 'alt__locale__'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{% extends 'BitBagSyliusCmsPlugin::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.new_'~metadata.name) %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.create' %} | ||
|
||
{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} | ||
|
||
{% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Create/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Create/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resource': resource}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
<link rel="stylesheet" href="{{ asset('bundles/bitbagsyliuscmsplugin/css/style.css') }}"> | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends 'BitBagSyliusCmsPlugin::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
|
||
{% set definition = resources.definition %} | ||
{% set data = resources.data %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.index' %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.'~metadata.pluralName) %} | ||
|
||
{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resources': resources}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Index/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resources': resources}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Index/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resources': resources}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} | ||
|
||
{% block javascripts %} | ||
{{ parent() }} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.javascripts') }} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{% extends 'BitBagSyliusCmsPlugin::layout.html.twig' %} | ||
|
||
{% import 'SyliusUiBundle:Macro:headers.html.twig' as headers %} | ||
{% import 'SyliusUiBundle:Macro:buttons.html.twig' as buttons %} | ||
|
||
{% set header = configuration.vars.header|default(metadata.applicationName~'.ui.edit_'~metadata.name) %} | ||
{% set event_prefix = metadata.applicationName ~ '.admin.' ~ metadata.name ~ '.update' %} | ||
|
||
{% block title %}{{ header|trans }} {{ parent() }}{% endblock %} | ||
|
||
{% form_theme form '@SyliusAdmin/Form/theme.html.twig' %} | ||
|
||
{% block content %} | ||
{{ sonata_block_render_event(event_prefix ~ '.before_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Update/_header.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_header', {'resource': resource}) }} | ||
|
||
{% include '@SyliusAdmin/Crud/Update/_content.html.twig' %} | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.after_content', {'resource': resource}) }} | ||
{% endblock %} | ||
|
||
{% block stylesheets %} | ||
{{ parent() }} | ||
|
||
<link rel="stylesheet" href="{{ asset('bundles/bitbagsyliuscmsplugin/css/style.css') }}"> | ||
|
||
{{ sonata_block_render_event(event_prefix ~ '.stylesheets') }} | ||
{% endblock %} |