Skip to content

Commit

Permalink
Conversion block accordion (#81)
Browse files Browse the repository at this point in the history
* prepare v2

* new integ for v2

* add missing preview controller

* prepare preview

* add better integ into catalog & folders

* add better integ into catalog & folders²

* remove dump

* Add assets optimization for multiple configurator

* change the way the image block is loaded

* fix wrong params

* Reset CSS for TheliaBlocks

* add shortcode & reworks blocks rendering

* optimize theliaBlocks shortcode

* remove debug value

* add linking capability

* Add locale handling for blockgroup

* Added props for BlocksList, CSS reset adjustments, patch annotation on group api route

* wip

* feat(documentation): first version (WIP)

* doc changes

* Doc changes : added documentation for external plugin

* Updated documentation, added examples and more

* Added command to convert old accordion blocks for new Thelia Blocks

* update blocks editor deps

* rebuild vendor

Co-authored-by: Vincent Lopes-Vicente <vlopes@openstudio.fr>
Co-authored-by: Mathis Chambon <matchambon60@gmail.com>
  • Loading branch information
3 people committed Sep 5, 2022
1 parent 20e5c40 commit f01adab
Show file tree
Hide file tree
Showing 14 changed files with 621 additions and 189 deletions.
91 changes: 91 additions & 0 deletions Command/ValidateJsonContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

namespace TheliaBlocks\Command;

use Propel\Runtime\ActiveQuery\ModelCriteria;
use Propel\Runtime\ActiveRecord\ActiveRecordInterface;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\File\File;
use Thelia\Command\ContainerAwareCommand;
use Thelia\Model\ConfigQuery;
use Thelia\Model\FolderImage;
use Thelia\Model\LangQuery;
use TheliaBlocks\Model\BlockGroupI18nQuery;

class ValidateJsonContent extends ContainerAwareCommand
{
public function __construct()
{
parent::__construct();
}

protected function configure(): void
{
$this
->setName('thelia_blocks:blocks:validate')
->setDescription('Validate & update json_content structure');
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$jsonContents = BlockGroupI18nQuery::create()->find();


$output->writeln('<bg=blue>============================================================= </>');
$output->writeln("<fg=blue>Thelia blocks json_content validation started</>");
$progressBar = new ProgressBar($output, $jsonContents->count());
$progressBar->start();

foreach ($jsonContents as $jsonContent) {
$content = $jsonContent->getJsonContent();

$decodedJson = json_decode($content, true);

foreach ($decodedJson as $key => $value) {
$output->writeln("-");
$output->writeln($value["type"]["id"]);

if ($value["type"]["id"] === "blockAccordion") {
$oldData = $decodedJson[$key]["data"];

$group = array_map(function ($item) {
if (isset($item["group"])) {
$item["content"] = [];
$item["content"][] = $item["group"];

unset($item["group"]);

$item["content"][0]["data"] = ["content" => [$item["content"][0]["data"]]];
}

return $item;
}, $oldData);

$decodedJson[$key]["data"] = [
"title" => "",
"group" => $group
];
}
}


$jsonContent->setJsonContent(json_encode($decodedJson));

$jsonContent->save();

$progressBar->advance();
}

$progressBar->finish();
$output->writeln("");
$output->writeln("<info>Thelia blocks json_content validation ended</info>");
$output->writeln('<bg=blue>============================================================= </>');

return 1;
}
}
2 changes: 1 addition & 1 deletion Model/Api/ItemBlockGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function createFromTheliaModel($theliaModel, $locale = null)
}

$tableMap = new $tableMapClass();
$queryClass = $tableMap->getClassName().'Query';
$queryClass = $tableMap->getClassName() . 'Query';

if (!class_exists($queryClass)) {
return $this;
Expand Down
Loading

0 comments on commit f01adab

Please sign in to comment.