Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ oro_layout:
enabled_themes:
- default
- acme
- new

oro_locale:
formatting_code: en
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Training\Bundle\NewThemeBundle\DependencyInjection;

use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
public const ROOT_NODE = 'training_new_theme';

/**
* {@inheritDoc}
*/
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder(self::ROOT_NODE);
$rootNode = $treeBuilder->getRootNode();

SettingsBuilder::append(
$rootNode,
[
'store_phone' => ['value' => '+19012345678'],
'store_support_email' => ['value' => 'mail@example.com'],
'store_youtube_channel' => ['value' => 'https://www.youtube.com/']
]
);

return $treeBuilder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Training\Bundle\NewThemeBundle\DependencyInjection;

use Oro\Bundle\ConfigBundle\DependencyInjection\SettingsBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class TrainingNewThemeExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');

$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);
$container->prependExtensionConfig($this->getAlias(), SettingsBuilder::getSettings($config));
}

public function getAlias(): string
{
return Configuration::ROOT_NODE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php

namespace Training\Bundle\NewThemeBundle\Migrations\Data\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Gaufrette\Adapter\Local;
use Gaufrette\Filesystem;
use Oro\Bundle\AttachmentBundle\Entity\File as AttachmentFile;
use Oro\Bundle\CMSBundle\Entity\ContentBlock;
use Oro\Bundle\CMSBundle\Entity\TextContentVariant;
use Oro\Bundle\DigitalAssetBundle\Entity\DigitalAsset;
use Oro\Bundle\LocaleBundle\Entity\LocalizedFallbackValue;
use Oro\Bundle\MigrationBundle\Fixture\VersionedFixtureInterface;
use Oro\Bundle\UserBundle\DataFixtures\UserUtilityTrait;
use Oro\Bundle\UserBundle\Entity\User;
use Oro\Bundle\UserBundle\Migrations\Data\ORM\LoadAdminUserData;
use Symfony\Component\Config\FileLocator;
use Oro\Component\DependencyInjection\ContainerAwareInterface;
use Oro\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\Yaml\Yaml;

/**
* Create or update content block based on data specified in file
*/
class LoadContentBlocksData extends AbstractFixture implements
DependentFixtureInterface,
ContainerAwareInterface,
VersionedFixtureInterface
{
use ContainerAwareTrait;
use UserUtilityTrait;

protected string $blocksConfigPath = '@TrainingNewThemeBundle/Migrations/Data/ORM/data/content_blocks.yml';

public function getDependencies()
{
return [
LoadAdminUserData::class
];
}

public function getVersion()
{
return '1.0';
}

public function load(ObjectManager $manager)
{
$user = $this->getFirstUser($manager);

$contentBlockRepository = $manager->getRepository(ContentBlock::class);
$rows = Yaml::parse(file_get_contents($this->getFilePathsFromLocator($this->blocksConfigPath)));

foreach ($rows as $blockName => $blockData) {
$contentBlock = $contentBlockRepository->findOneBy(['alias' => $blockName]);
if ($contentBlock) {
$this->updateExistingBlock($contentBlock, $blockData, $manager);
continue;
}

$this->createNewBlock($blockName, $blockData, $manager, $user);
}

$manager->flush();
}

private function updateExistingBlock(ContentBlock $contentBlock, array $blockData, ObjectManager $manager): void
{
$title = $contentBlock->getDefaultTitle();
$title->setString($blockData['title']);

$variants = $contentBlock->getContentVariants();
foreach ($variants as $variant) {
if (!$variant->isDefault()) {
continue;
}
$variant->setContent($blockData['content']);
}
$manager->persist($contentBlock);
}

private function createNewBlock(string $blockName, array $blockData, ObjectManager $manager, User $user): void
{
$title = new LocalizedFallbackValue();
$title->setString($blockData['title']);
$manager->persist($title);

$variant = new TextContentVariant();
$variant->setDefault(true);
$variant->setContent($blockData['content']);

$manager->persist($variant);

$contentBlock = new ContentBlock();
$contentBlock->setOrganization($user->getOrganization());
$contentBlock->setOwner($user->getOwner());
$contentBlock->setAlias($blockName);
$contentBlock->addTitle($title);
$contentBlock->addContentVariant($variant);
$manager->persist($contentBlock);
}

protected function getFilePathsFromLocator(string $path): array|string
{
$locator = $this->container->get('file_locator');
return $locator->locate($path);
}

protected function createImage(
ObjectManager $manager,
User $user,
string $fileRoot,
string $filename,
string $fileExtension
): AttachmentFile {
$locator = $this->container->get('file_locator');

$imagePath = $locator->locate(sprintf('%s/%s.%s', $fileRoot, $filename, $fileExtension));
if (is_array($imagePath)) {
$imagePath = current($imagePath);
}

$file = $this->container->get('oro_attachment.file_manager')->createFileEntity($imagePath);
$file->setOwner($user);
$manager->persist($file);

$imageTitle = new LocalizedFallbackValue();
$imageTitle->setString($filename);
$manager->persist($imageTitle);

$digitalAsset = new DigitalAsset();
$digitalAsset->addTitle($imageTitle)
->setSourceFile($file)
->setOwner($user)
->setOrganization($user->getOrganization());
$manager->persist($digitalAsset);

$image = new AttachmentFile();
$image->setDigitalAsset($digitalAsset);
$manager->persist($image);
$manager->flush();

$this->writeDigitalAssets($file, $locator, $fileRoot, $filename, $fileExtension, 'original');

return $image;
}

protected function writeDigitalAssets(
AttachmentFile $file,
FileLocator $locator,
string $fileRoot,
string $filename,
string $fileExtension,
string $filter
): void {
$storagePath = $this->container->get('oro_attachment.provider.resized_image_path')
->getPathForFilteredImage($file, $filter);

$rootPath = $locator->locate($fileRoot);
if (is_array($rootPath)) {
$rootPath = current($rootPath);
}

$filesystem = new Filesystem(new Local($rootPath, false, 0600));

$file = $filesystem->get(sprintf('%s.%s', $filename, $fileExtension));

$this->container->get('oro_attachment.manager.protected_mediacache')
->writeToStorage($file->getContent(), $storagePath);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
footer-social:
title: Footer Social
content: >
<div class="footer__social">
<span class="footer__social-title">Follow ORO:</span>
<div class="footer__social-items">
<a href="https://www.facebook.com/OroCommerce-333319140210515/" target="_blank" class="footer__social-link"><img alt="Oro facebook" src="/bundles/trainingnewtheme/new/images/facebook.svg"></a>
<a href="https://www.linkedin.com/company/oro-inc-" target="_blank" class="footer__social-link"><img alt="Oro linkedin" class=" lazyloaded" src="/bundles/trainingnewtheme/new/images/linkedin.svg"></a>
<a href="https://twitter.com/OroCommerce " target="_blank" class="footer__social-link"><img alt="Oro twitter" class=" lazyloaded" src="/bundles/trainingnewtheme/new/images/twitter.svg"></a>
<a href="https://www.youtube.com/channel/UClxsA8HS9KGEEsvFRn7JkvQ" target="_blank" class="footer__social-link"><img alt="Oro Youtube" class=" lazyloaded" src="/bundles/trainingnewtheme/new/images/youtube.svg"></a>
</div>
</div>
11 changes: 11 additions & 0 deletions src/Training/Bundle/NewThemeBundle/Resources/config/oro/app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
oro_theme:
themes:
oro:
logo: bundles/trainingnewtheme/oro/images/logo.svg
icon: bundles/trainingnewtheme/oro/images/favicons/favicon.ico

oro_layout:
active_theme: new
enabled_themes:
- new
- default
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
css:
inputs:
# Styles
- 'bundles/trainingnewtheme/oro/css/scss/main.scss'
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bundles:
- { name: Training\Bundle\NewThemeBundle\TrainingNewThemeBundle, priority: 1001 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
system_configuration:
groups:
store_media_settings:
title: training.theme.system_configuration.groups.store_media_settings.title

fields:
training_new_theme.store_phone:
data_type: string
type: Symfony\Component\Form\Extension\Core\Type\TextType
search_type: text
priority: 100
options:
label: training.theme.system_configuration.store_media_settings.store_phone.label
required: false

training_new_theme.store_support_email:
data_type: string
type: Symfony\Component\Form\Extension\Core\Type\TextType
search_type: text
priority: 90
options:
label: training.theme.system_configuration.store_media_settings.store_email.label
required: false

training_new_theme.store_youtube_channel:
data_type: string
type: Symfony\Component\Form\Extension\Core\Type\TextType
search_type: text
priority: 90
options:
label: training.theme.system_configuration.store_media_settings.store_youtube_channel.label
required: false
constraints:
- Url: ~

tree:
system_configuration:
commerce:
children:
design:
children:
theme:
children:
store_media_settings:
priority: -200
children:
- training_new_theme.store_phone
- training_new_theme.store_support_email
- training_new_theme.store_youtube_channel
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
new_theme.provider.new_image_placeholder.default:
parent: oro_layout.provider.image_placeholder.default.abstract
public: false
arguments:
- '/bundles/trainingnewtheme/new/images/no_image.svg'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading