-
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.
Merge pull request #28 from pyrorules/master
Added block fixtures
- Loading branch information
Showing
6 changed files
with
313 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?php | ||
|
||
/** | ||
* This file was created by the 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 [email protected]. | ||
*/ | ||
|
||
namespace BitBag\CmsPlugin\Fixture; | ||
|
||
use BitBag\CmsPlugin\Entity\Block; | ||
use BitBag\CmsPlugin\Entity\BlockInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @author Wojciech Górski <[email protected]> | ||
*/ | ||
final class HtmlBlockFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $blockManager; | ||
|
||
/** | ||
* @param EntityManagerInterface $blockManager | ||
*/ | ||
public function __construct(EntityManagerInterface $blockManager) | ||
{ | ||
$this->blockManager = $blockManager; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function load(array $options) | ||
{ | ||
$block = new Block(); | ||
|
||
$block->setCode($options['code']); | ||
$block->setType(BlockInterface::HTML_BLOCK_TYPE); | ||
|
||
foreach ($options['translations'] as $translation) { | ||
$block->setCurrentLocale($translation['locale']); | ||
$block->setName($translation['name']); | ||
$block->setContent($translation['content']); | ||
} | ||
|
||
$this->blockManager->persist($block); | ||
|
||
$this->blockManager->flush(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName() | ||
{ | ||
return 'bitbag_cms_block_html'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode) | ||
{ | ||
$optionsNode | ||
->children() | ||
->scalarNode('code')->isRequired()->cannotBeEmpty()->end() | ||
->arrayNode('translations') | ||
->prototype('array') | ||
->children() | ||
->scalarNode('locale')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('name')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('content')->isRequired()->cannotBeEmpty()->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
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,113 @@ | ||
<?php | ||
|
||
/** | ||
* This file was created by the 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 [email protected]. | ||
*/ | ||
|
||
namespace BitBag\CmsPlugin\Fixture; | ||
|
||
use BitBag\CmsPlugin\Entity\Block; | ||
use BitBag\CmsPlugin\Entity\BlockInterface; | ||
use BitBag\CmsPlugin\Entity\Image; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Sylius\Component\Core\Uploader\ImageUploaderInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
use Symfony\Component\HttpFoundation\File\File; | ||
|
||
/** | ||
* @author Wojciech Górski <[email protected]> | ||
*/ | ||
final class ImageBlockFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $blockManager; | ||
|
||
/** | ||
* @var ImageUploaderInterface | ||
*/ | ||
private $imageUploader; | ||
|
||
/** | ||
* @param EntityManagerInterface $blockManager | ||
* @param ImageUploaderInterface $imageUploader | ||
*/ | ||
public function __construct(EntityManagerInterface $blockManager, ImageUploaderInterface $imageUploader) | ||
{ | ||
$this->blockManager = $blockManager; | ||
$this->imageUploader = $imageUploader; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function load(array $options) | ||
{ | ||
$block = new Block(); | ||
|
||
$block->setCode($options['code']); | ||
$block->setType(BlockInterface::IMAGE_BLOCK_TYPE); | ||
|
||
foreach ($options['translations'] as $translation) { | ||
$block->setCurrentLocale($translation['locale']); | ||
$block->setName($translation['name']); | ||
$block->setLink($translation['link']); | ||
|
||
$file = new File($translation['image']['filePath']); | ||
|
||
$image = new Image(); | ||
$image->setFile($file); | ||
$image->setType($translation['image']['type']); | ||
|
||
$this->imageUploader->upload($image); | ||
|
||
$block->setImage($image); | ||
} | ||
|
||
$this->blockManager->persist($block); | ||
|
||
$this->blockManager->flush(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName() | ||
{ | ||
return 'bitbag_cms_block_image'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode) | ||
{ | ||
$optionsNode | ||
->children() | ||
->scalarNode('code')->isRequired()->cannotBeEmpty()->end() | ||
->arrayNode('translations') | ||
->prototype('array') | ||
->children() | ||
->scalarNode('locale')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('name')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('link')->isRequired()->cannotBeEmpty()->end() | ||
->arrayNode('image') | ||
->children() | ||
->scalarNode('type')->end() | ||
->scalarNode('filePath')->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
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,87 @@ | ||
<?php | ||
|
||
/** | ||
* This file was created by the 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 [email protected]. | ||
*/ | ||
|
||
namespace BitBag\CmsPlugin\Fixture; | ||
|
||
use BitBag\CmsPlugin\Entity\Block; | ||
use BitBag\CmsPlugin\Entity\BlockInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sylius\Bundle\FixturesBundle\Fixture\AbstractFixture; | ||
use Sylius\Bundle\FixturesBundle\Fixture\FixtureInterface; | ||
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; | ||
|
||
/** | ||
* @author Wojciech Górski <[email protected]> | ||
*/ | ||
final class TextBlockFixture extends AbstractFixture implements FixtureInterface | ||
{ | ||
/** | ||
* @var EntityManagerInterface | ||
*/ | ||
private $blockManager; | ||
|
||
/** | ||
* @param EntityManagerInterface $blockManager | ||
*/ | ||
public function __construct(EntityManagerInterface $blockManager) | ||
{ | ||
$this->blockManager = $blockManager; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function load(array $options) | ||
{ | ||
$block = new Block(); | ||
|
||
$block->setCode($options['code']); | ||
$block->setType(BlockInterface::TEXT_BLOCK_TYPE); | ||
|
||
foreach ($options['translations'] as $translation) { | ||
$block->setCurrentLocale($translation['locale']); | ||
$block->setName($translation['name']); | ||
$block->setContent($translation['content']); | ||
} | ||
|
||
$this->blockManager->persist($block); | ||
|
||
$this->blockManager->flush(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getName() | ||
{ | ||
return 'bitbag_cms_block_text'; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode) | ||
{ | ||
$optionsNode | ||
->children() | ||
->scalarNode('code')->isRequired()->cannotBeEmpty()->end() | ||
->arrayNode('translations') | ||
->prototype('array') | ||
->children() | ||
->scalarNode('locale')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('name')->isRequired()->cannotBeEmpty()->end() | ||
->scalarNode('content')->isRequired()->cannotBeEmpty()->end() | ||
->end() | ||
->end() | ||
->end() | ||
->end() | ||
; | ||
} | ||
} |
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,2 @@ | ||
imports: | ||
- { resource: "@BitBagCmsPlugin/Resources/config/fixture/block.yml" } |
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,22 @@ | ||
services: | ||
bitbag.cms_plugin.fixture.html_block: | ||
class: BitBag\CmsPlugin\Fixture\HtmlBlockFixture | ||
arguments: | ||
- '@bitbag.manager.block' | ||
tags: | ||
- { name: sylius_fixtures.fixture } | ||
|
||
bitbag.cms_plugin.fixture.text_block: | ||
class: BitBag\CmsPlugin\Fixture\TextBlockFixture | ||
arguments: | ||
- '@bitbag.manager.block' | ||
tags: | ||
- { name: sylius_fixtures.fixture } | ||
|
||
bitbag.cms_plugin.fixture.image_block: | ||
class: BitBag\CmsPlugin\Fixture\ImageBlockFixture | ||
arguments: | ||
- '@bitbag.manager.block' | ||
- '@sylius.image_uploader' | ||
tags: | ||
- { name: sylius_fixtures.fixture } |