Compare commits
104 commits
Author | SHA1 | Date | |
---|---|---|---|
Simon Vieille | eb376dc36c | ||
Simon Vieille | 8e947b0b77 | ||
Simon Vieille | fd1a45c0e7 | ||
Simon Vieille | bc148f0b6b | ||
Simon Vieille | 4a3619919c | ||
Simon Vieille | 4054f6ccff | ||
Simon Vieille | 01ecac272e | ||
Simon Vieille | 89efd5475f | ||
Simon Vieille | 029d296bd8 | ||
Simon Vieille | 1120c20f05 | ||
Simon Vieille | f4a70bec66 | ||
Simon Vieille | d4ba8dc619 | ||
Simon Vieille | 26e422619b | ||
Simon Vieille | eb3c1a8879 | ||
Simon Vieille | 9963c4b3cf | ||
Simon Vieille | e322973e67 | ||
Simon Vieille | a15cf1559b | ||
Simon Vieille | 006b8cdbe6 | ||
Simon Vieille | 46f13d817d | ||
Simon Vieille | 0d5f248ca9 | ||
Simon Vieille | d1ca98eddd | ||
Simon Vieille | 62fbd936c6 | ||
Simon Vieille | d66fb7da78 | ||
Simon Vieille | 57dd7da162 | ||
Simon Vieille | d7ce3cb12f | ||
Simon Vieille | fea5319dc5 | ||
Simon Vieille | ff0ab092e4 | ||
Simon Vieille | a0211026ba | ||
Simon Vieille | c5dde3b184 | ||
Simon Vieille | b1ea641374 | ||
Simon Vieille | 62de6416c5 | ||
Simon Vieille | 246c249d3e | ||
Simon Vieille | be26d15b22 | ||
Simon Vieille | 3f5bd4f950 | ||
Simon Vieille | a80dc9999c | ||
Simon Vieille | b9566853ef | ||
Simon Vieille | bc7e8ef263 | ||
Simon Vieille | 25efd11ea3 | ||
Simon Vieille | e23f7d3c73 | ||
Simon Vieille | 85f054956c | ||
Simon Vieille | b12f4db16f | ||
Simon Vieille | 6bb29dd5c3 | ||
Simon Vieille | 7824e96bab | ||
Simon Vieille | 56177c14da | ||
Simon Vieille | 4f1c5b8f14 | ||
Simon Vieille | e8c9520378 | ||
Simon Vieille | 283223446a | ||
Simon Vieille | 46e01f504f | ||
Simon Vieille | a80ee03fcd | ||
Simon Vieille | d1649a4959 | ||
Simon Vieille | 38791f1d7a | ||
Simon Vieille | d74cd52711 | ||
Simon Vieille | b451df61e8 | ||
Simon Vieille | 7c124008c0 | ||
Simon Vieille | 9cf95dba64 | ||
Simon Vieille | b680946daf | ||
Simon Vieille | 1995298977 | ||
Simon Vieille | 4acba618cb | ||
Simon Vieille | 92eaaba699 | ||
Simon Vieille | 357856f8ce | ||
Simon Vieille | dfbe282d0e | ||
Simon Vieille | 857fcd9897 | ||
Simon Vieille | 48ca5a96e6 | ||
Simon Vieille | 065bb0db22 | ||
Simon Vieille | bf6777054f | ||
Simon Vieille | 51acd82432 | ||
Simon Vieille | c6cbc405e4 | ||
Simon Vieille | 150f3afd6a | ||
Simon Vieille | 4a0e616897 | ||
Simon Vieille | 4eb13a4022 | ||
Simon Vieille | 8bb6267a77 | ||
Simon Vieille | 8044ff3605 | ||
Simon Vieille | 71d3d40d5f | ||
Simon Vieille | 9324837bd9 | ||
Simon Vieille | b8dfaaed10 | ||
Simon Vieille | 2d49b8ddee | ||
Simon Vieille | 232b92267e | ||
Simon Vieille | ca23a22807 | ||
Simon Vieille | 78965bbf10 | ||
Simon Vieille | 7fe1acd47d | ||
Simon Vieille | 26cbaa8469 | ||
Simon Vieille | 7897bafcc2 | ||
Simon Vieille | 63a8a60e2d | ||
Simon Vieille | d01e9d618b | ||
Simon Vieille | 96347a1730 | ||
Simon Vieille | aeb0e6c109 | ||
Simon Vieille | 64258a2d8c | ||
Simon Vieille | 70329ceeda | ||
Simon Vieille | 1adb1ebe2b | ||
Simon Vieille | f57cc8e4d6 | ||
Simon Vieille | b21967028e | ||
Simon Vieille | 5b22851674 | ||
Simon Vieille | 4082bb171a | ||
Simon Vieille | dc19617fb1 | ||
Simon Vieille | dbd2036fb0 | ||
Simon Vieille | 8e2566abc8 | ||
Simon Vieille | 66e1a9c87f | ||
Simon Vieille | 6709c0a303 | ||
Simon Vieille | 614ae40901 | ||
Simon Vieille | 430bff9433 | ||
Simon Vieille | 6441da8a27 | ||
Simon Vieille | 801e3317e7 | ||
Simon Vieille | f7604d2a45 | ||
Simon Vieille | 8a632a1b14 |
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,5 +1,24 @@
|
|||
## [Unreleased]
|
||||
|
||||
## [v1.25.1] - 2024-05-13
|
||||
### Added
|
||||
* add drag&drop in the block builder
|
||||
|
||||
## [v1.25.0] - 2024-05-12
|
||||
### Added
|
||||
* add block builder widget
|
||||
* allow to use `window.tinymceModes` to add or override tinymce modes
|
||||
* add border color on tinymce editor
|
||||
### Fixed
|
||||
* fix default crud sort
|
||||
* fix hidden save button in file manager
|
||||
* fix template of CrudController (maker)
|
||||
* fix undefined `window.tinymce.murph`
|
||||
|
||||
## [v1.24.1] - 2024-02-01
|
||||
### Fixed
|
||||
* update Murph version constant
|
||||
|
||||
## [v1.24.0] - 2024-01-27
|
||||
### Added
|
||||
* add CSS class `no-wrap`
|
||||
|
|
47
src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php
Normal file
47
src/core/BuilderBlock/Block/Bootstrap/AlertBlock.php
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class AlertBlock extends BootstrapBlock
|
||||
{
|
||||
public function __construct(protected TranslatorInterface $translator)
|
||||
{
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$options = [];
|
||||
|
||||
foreach ([
|
||||
'Primary' => 'primary',
|
||||
'Secondary' => 'secondary',
|
||||
'Info' => 'info',
|
||||
'Success' => 'success',
|
||||
'Danger' => 'danger',
|
||||
'Warning' => 'warning',
|
||||
'Light' => 'light',
|
||||
'Dark' => 'dark',
|
||||
] as $k => $v) {
|
||||
$options[] = [
|
||||
'text' => $this->translator->trans($k),
|
||||
'value' => $v,
|
||||
];
|
||||
}
|
||||
|
||||
$this
|
||||
->setName('bsAlert')
|
||||
->setLabel('Alert')
|
||||
->setOrder(4)
|
||||
->setIsContainer(true)
|
||||
->setIcon('<i class="fas fa-exclamation-circle"></i>')
|
||||
->setTemplate('@Core/builder_block/bootstrap/alert.html.twig')
|
||||
->addSetting(name: 'level', label: 'Level', type: 'select', extraOptions: ['options' => $options])
|
||||
;
|
||||
}
|
||||
}
|
14
src/core/BuilderBlock/Block/Bootstrap/BootstrapBlock.php
Normal file
14
src/core/BuilderBlock/Block/Bootstrap/BootstrapBlock.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
class BootstrapBlock extends BuilderBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setCategory('Bootstrap');
|
||||
}
|
||||
}
|
31
src/core/BuilderBlock/Block/Bootstrap/ColumnBlock.php
Normal file
31
src/core/BuilderBlock/Block/Bootstrap/ColumnBlock.php
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class ColumnBlock extends BootstrapBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('bsColumn')
|
||||
->setLabel('Column')
|
||||
->setIsContainer(true)
|
||||
->setOrder(3)
|
||||
->setClass('col-12 col-lg-3 pr-md-1')
|
||||
->setTemplate('@Core/builder_block/bootstrap/column.html.twig')
|
||||
->setIcon('<i class="fas fa-columns"></i>')
|
||||
->addSetting(name: 'size', label: 'Extra small', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeSm', label: 'Small', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeMd', label: 'Medium', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeLg', label: 'Large', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'sizeXl', label: 'Extra large', type: 'number', attributes: ['min' => 0, 'max' => 12])
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
26
src/core/BuilderBlock/Block/Bootstrap/ContainerBlock.php
Normal file
26
src/core/BuilderBlock/Block/Bootstrap/ContainerBlock.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class ContainerBlock extends BootstrapBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('bsContainer')
|
||||
->setLabel('Container')
|
||||
->setIsContainer(true)
|
||||
->setOrder(1)
|
||||
->setTemplate('@Core/builder_block/bootstrap/container.html.twig')
|
||||
->setIcon('<i class="fas fa-th"></i>')
|
||||
->addSetting(name: 'isFluid', label: 'Fluid', type: 'checkbox')
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
26
src/core/BuilderBlock/Block/Bootstrap/RowBlock.php
Normal file
26
src/core/BuilderBlock/Block/Bootstrap/RowBlock.php
Normal file
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Bootstrap;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class RowBlock extends BootstrapBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('bsRow')
|
||||
->setLabel('Row')
|
||||
->setOrder(2)
|
||||
->setIsContainer(true)
|
||||
->setIcon('<i class="fas fa-align-justify"></i>')
|
||||
->setTemplate('@Core/builder_block/bootstrap/row.html.twig')
|
||||
->addWidget('bsColumn')
|
||||
->addSetting(name: 'customClass', label: 'Custom class', type: 'text')
|
||||
;
|
||||
}
|
||||
}
|
14
src/core/BuilderBlock/Block/Editor/EditorBlock.php
Normal file
14
src/core/BuilderBlock/Block/Editor/EditorBlock.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Editor;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
class EditorBlock extends BuilderBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->setCategory('Editors');
|
||||
}
|
||||
}
|
27
src/core/BuilderBlock/Block/Editor/TextareaBlock.php
Normal file
27
src/core/BuilderBlock/Block/Editor/TextareaBlock.php
Normal file
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Editor;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class TextareaBlock extends EditorBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('textarea')
|
||||
->setLabel('Text')
|
||||
->setIsContainer(false)
|
||||
->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
->setTemplate('@Core/builder_block/editor/textarea.html.twig')
|
||||
->addSetting(name: 'nl2br', label: 'Insert line breaks', type: 'checkbox', default: true)
|
||||
->addSetting(name: 'allowHtml', label: 'Allow HTML', type: 'checkbox', default: false)
|
||||
->addSetting(name: 'value', type: 'textarea')
|
||||
->setPreview('value')
|
||||
;
|
||||
}
|
||||
}
|
25
src/core/BuilderBlock/Block/Editor/TinymceBlock.php
Normal file
25
src/core/BuilderBlock/Block/Editor/TinymceBlock.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock\Block\Editor;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class TinymceBlock extends EditorBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
|
||||
$this
|
||||
->setName('tinymce')
|
||||
->setLabel('TinyMCE')
|
||||
->setIsContainer(false)
|
||||
->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
->setTemplate('@Core/builder_block/editor/tinymce.html.twig')
|
||||
->addSetting(name: 'value', type: 'textarea', attributes: ['data-tinymce' => ''])
|
||||
->setPreview('value')
|
||||
;
|
||||
}
|
||||
}
|
209
src/core/BuilderBlock/BuilderBlock.php
Normal file
209
src/core/BuilderBlock/BuilderBlock.php
Normal file
|
@ -0,0 +1,209 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock;
|
||||
|
||||
abstract class BuilderBlock
|
||||
{
|
||||
protected string $name;
|
||||
protected string $label;
|
||||
protected ?string $class = 'col-12';
|
||||
protected ?string $category = null;
|
||||
protected array $settings = [];
|
||||
protected array $widgets = [];
|
||||
protected array $vars = [];
|
||||
protected string $template = '';
|
||||
protected ?string $preview = null;
|
||||
protected bool $isContainer = false;
|
||||
protected ?string $icon = null;
|
||||
protected int $order = 1;
|
||||
|
||||
abstract public function configure();
|
||||
|
||||
public function setLabel(string $label): self
|
||||
{
|
||||
$this->label = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLabel(): string
|
||||
{
|
||||
return $this->label;
|
||||
}
|
||||
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setCategory(?string $category): self
|
||||
{
|
||||
$this->category = $category;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCategory(): ?string
|
||||
{
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
public function setIsContainer(bool $isContainer): self
|
||||
{
|
||||
$this->isContainer = $isContainer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIsContainer(): bool
|
||||
{
|
||||
return $this->isContainer;
|
||||
}
|
||||
|
||||
public function setWidgets(array $widgets): self
|
||||
{
|
||||
$this->widgets = $widgets;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addWidget(string $widget): self
|
||||
{
|
||||
if (!in_array($widget, $this->widgets)) {
|
||||
$this->widgets[] = $widget;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
return $this->widgets;
|
||||
}
|
||||
|
||||
public function setSettings(array $settings): self
|
||||
{
|
||||
$this->settings = $settings;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addSetting(
|
||||
string $name,
|
||||
string $type = 'input',
|
||||
?string $label = null,
|
||||
array $attributes = [],
|
||||
array $extraOptions = [],
|
||||
$default = null
|
||||
) {
|
||||
$this->settings[$name] = [
|
||||
'label' => $label,
|
||||
'type' => $type,
|
||||
'attr' => $attributes,
|
||||
'default' => $default,
|
||||
];
|
||||
|
||||
foreach ($extraOptions as $key => $value) {
|
||||
if (!in_array($key, array_keys($this->settings[$name]))) {
|
||||
$this->settings[$name][$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSettings(): array
|
||||
{
|
||||
return $this->settings;
|
||||
}
|
||||
|
||||
public function setTemplate(string $template): self
|
||||
{
|
||||
$this->template = $template;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getTemplate(): string
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
public function setClass(?string $class): self
|
||||
{
|
||||
$this->class = $class;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getClass(): ?string
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
public function setIcon(?string $icon): self
|
||||
{
|
||||
$this->icon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getIcon(): ?string
|
||||
{
|
||||
return $this->icon;
|
||||
}
|
||||
|
||||
public function setOrder(int $order): self
|
||||
{
|
||||
$this->order = $order;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getOrder(): int
|
||||
{
|
||||
return $this->order;
|
||||
}
|
||||
|
||||
public function setPreview(?string $preview): self
|
||||
{
|
||||
$this->preview = $preview;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPreview(): ?string
|
||||
{
|
||||
return $this->preview;
|
||||
}
|
||||
|
||||
public function buildVars(array $data, array $context)
|
||||
{
|
||||
}
|
||||
|
||||
public function getVars(): array
|
||||
{
|
||||
return $this->vars;
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'label' => $this->getLabel(),
|
||||
'category' => $this->getCategory(),
|
||||
'isContainer' => $this->getIsContainer(),
|
||||
'widgets' => $this->getWidgets(),
|
||||
'settings' => $this->getSettings(),
|
||||
'class' => $this->getClass(),
|
||||
'icon' => $this->getIcon(),
|
||||
'preview' => $this->getPreview(),
|
||||
];
|
||||
}
|
||||
}
|
41
src/core/BuilderBlock/BuilderBlockContainer.php
Normal file
41
src/core/BuilderBlock/BuilderBlockContainer.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\BuilderBlock;
|
||||
|
||||
class BuilderBlockContainer
|
||||
{
|
||||
protected array $widgets = [];
|
||||
|
||||
public function addWidget(BuilderBlock $widget): self
|
||||
{
|
||||
$widget->configure();
|
||||
|
||||
$this->widgets[$widget->getName()] = $widget;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function removeWidget(string $name)
|
||||
{
|
||||
unset($this->widgets[$name]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getWidgets(): array
|
||||
{
|
||||
usort($this->widgets, fn(BuilderBlock $a, BuilderBlock $b) => $a->getOrder() <=> $b->getOrder());
|
||||
|
||||
return $this->widgets;
|
||||
}
|
||||
|
||||
public function hasWidget(string $name)
|
||||
{
|
||||
return isset($this->widgets[$name]);
|
||||
}
|
||||
|
||||
public function getWidget(string $name): BuilderBlock
|
||||
{
|
||||
return $this->widgets[$name];
|
||||
}
|
||||
}
|
|
@ -424,15 +424,14 @@ abstract class CrudController extends AdminController
|
|||
$sessionSortName = sprintf('%s_label', $sessionId);
|
||||
$sessionSortDirection = sprintf('%s_direction', $sessionId);
|
||||
|
||||
$name = $request->query->get(
|
||||
'_sort',
|
||||
$session->get($sessionSortName, $defaultSort['label'] ?? null)
|
||||
);
|
||||
$name = $request->query->get('_sort', $session->get($sessionSortName)) ?? $defaultSort['label'] ?? null;
|
||||
|
||||
$direction = strtolower($request->query->get(
|
||||
$direction = strtolower(
|
||||
$request->query->get(
|
||||
'_sort_direction',
|
||||
$session->get($sessionSortDirection, $defaultSort['direction'] ?? 'asc')
|
||||
));
|
||||
$session->get($sessionSortDirection)
|
||||
) ?? $defaultSort['direction'] ?? 'asc'
|
||||
);
|
||||
|
||||
$session->set($sessionSortName, $name);
|
||||
$session->set($sessionSortDirection, $direction);
|
||||
|
|
41
src/core/Controller/Editor/BuilderBlockController.php
Normal file
41
src/core/Controller/Editor/BuilderBlockController.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Controller\Editor;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlockContainer;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
#[Route(path: '/admin/editor/builder_block')]
|
||||
class BuilderBlockController extends AbstractController
|
||||
{
|
||||
public function __construct(protected TranslatorInterface $translator)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route(path: '/widgets', name: 'admin_editor_builder_block_widgets', options: ['expose' => true])]
|
||||
public function widgets(BuilderBlockContainer $container): JsonResponse
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($container->getWidgets() as $widget) {
|
||||
$data[$widget->getName()] = $this->translate($widget->toArray());
|
||||
}
|
||||
|
||||
return $this->json($data);
|
||||
}
|
||||
|
||||
protected function translate(array $data)
|
||||
{
|
||||
$data['label'] = $this->translator->trans($data['label']);
|
||||
$data['category'] = $this->translator->trans($data['category']);
|
||||
|
||||
foreach ($data['settings'] as $key => $value) {
|
||||
$data['settings'][$key]['label'] = $this->translator->trans($data['settings'][$key]['label']);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
25
src/core/DependencyInjection/Compiler/BuilderBlockPass.php
Normal file
25
src/core/DependencyInjection/Compiler/BuilderBlockPass.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use App\Core\BuilderBlock\BuilderBlockContainer;
|
||||
|
||||
class BuilderBlockPass implements CompilerPassInterface
|
||||
{
|
||||
public function process(ContainerBuilder $container): void
|
||||
{
|
||||
if (!$container->has(BuilderBlockContainer::class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->findDefinition(BuilderBlockContainer::class);
|
||||
$taggedServices = $container->findTaggedServiceIds('builder_block.widget');
|
||||
|
||||
foreach ($taggedServices as $id => $tags) {
|
||||
$definition->addMethodCall('addWidget', [new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -138,7 +138,7 @@ class Configuration implements ConfigurationInterface
|
|||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
->end();
|
||||
;
|
||||
|
||||
return $treeBuilder;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Core\DependencyInjection;
|
||||
|
||||
use App\Core\DependencyInjection\Compiler\BuilderBlockPass;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Extension\Extension;
|
||||
|
||||
|
|
20
src/core/Entity/Site/Page/BuilderBlock.php
Normal file
20
src/core/Entity/Site/Page/BuilderBlock.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Entity\Site\Page;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
class BuilderBlock extends JsonBlock
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
$value = parent::getValue();
|
||||
|
||||
if (is_string($value)) {
|
||||
return json_decode($value, true);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -5,15 +5,6 @@ namespace App\Core\Entity\Site\Page;
|
|||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
class ChoiceBlock extends Block
|
||||
class ChoiceBlock extends JsonBlock
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return json_decode(parent::getValue(), true);
|
||||
}
|
||||
|
||||
public function setValue($value): self
|
||||
{
|
||||
return parent::setValue(json_encode($value));
|
||||
}
|
||||
}
|
||||
|
|
19
src/core/Entity/Site/Page/JsonBlock.php
Normal file
19
src/core/Entity/Site/Page/JsonBlock.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Entity\Site\Page;
|
||||
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity]
|
||||
class JsonBlock extends Block
|
||||
{
|
||||
public function getValue()
|
||||
{
|
||||
return json_decode(parent::getValue(), true);
|
||||
}
|
||||
|
||||
public function setValue($value): self
|
||||
{
|
||||
return parent::setValue(json_encode($value));
|
||||
}
|
||||
}
|
32
src/core/Form/Site/Page/BuilderBlockType.php
Normal file
32
src/core/Form/Site/Page/BuilderBlockType.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Form\Site\Page;
|
||||
|
||||
use App\Core\Entity\Site\Page\BuilderBlock;
|
||||
use App\Core\Form\Type\BuilderType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class BuilderBlockType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder->add(
|
||||
'value',
|
||||
BuilderType::class,
|
||||
array_merge([
|
||||
'required' => false,
|
||||
'label' => false,
|
||||
], $options['options']),
|
||||
);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => BuilderBlock::class,
|
||||
'options' => [],
|
||||
]);
|
||||
}
|
||||
}
|
38
src/core/Form/Type/BuilderType.php
Normal file
38
src/core/Form/Type/BuilderType.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Form\Type;
|
||||
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType as BaseCollectionType;
|
||||
use Symfony\Component\Form\FormInterface;
|
||||
use Symfony\Component\Form\FormView;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
|
||||
|
||||
class BuilderType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildView(FormView $view, FormInterface $form, array $options)
|
||||
{
|
||||
parent::buildView($view, $form, $options);
|
||||
|
||||
$view->vars = array_replace($view->vars, [
|
||||
]);
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
parent::configureOptions($resolver);
|
||||
|
||||
$resolver->setDefaults([
|
||||
'compound' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'builder';
|
||||
}
|
||||
}
|
97
src/core/Maker/MakeBuilderBlock.php
Normal file
97
src/core/Maker/MakeBuilderBlock.php
Normal file
|
@ -0,0 +1,97 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Maker;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Symfony\Bundle\MakerBundle\ConsoleStyle;
|
||||
use Symfony\Bundle\MakerBundle\DependencyBuilder;
|
||||
use Symfony\Bundle\MakerBundle\Generator;
|
||||
use Symfony\Bundle\MakerBundle\InputConfiguration;
|
||||
use Symfony\Bundle\MakerBundle\Maker\AbstractMaker;
|
||||
use Symfony\Bundle\MakerBundle\Str;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Question\Question;
|
||||
use Symfony\Component\Filesystem\Filesystem;
|
||||
|
||||
class MakeBuilderBlock extends AbstractMaker
|
||||
{
|
||||
public static function getCommandName(): string
|
||||
{
|
||||
return 'make:builder-block';
|
||||
}
|
||||
|
||||
public static function getCommandDescription(): string
|
||||
{
|
||||
return 'Creates a new builder block class';
|
||||
}
|
||||
|
||||
public function configureCommand(Command $command, InputConfiguration $inputConf)
|
||||
{
|
||||
$command
|
||||
->addArgument(
|
||||
'builder-block-class',
|
||||
InputArgument::OPTIONAL,
|
||||
'Choose a name for your block class (e.g. <fg=yellow>ExampleBlock</>)'
|
||||
)
|
||||
->setHelp('')
|
||||
;
|
||||
}
|
||||
|
||||
public function generate(InputInterface $input, ConsoleStyle $io, Generator $generator)
|
||||
{
|
||||
$blockClassNameDetails = $generator->createClassNameDetails(
|
||||
$input->getArgument('builder-block-class'),
|
||||
'BuilderBlock\\',
|
||||
'Block'
|
||||
);
|
||||
|
||||
$templatePath = sprintf(
|
||||
'builder_block/%s.html.twig',
|
||||
Str::asSnakeCase(preg_replace('/Block$/', '', $blockClassNameDetails->getShortName()))
|
||||
);
|
||||
|
||||
$options = [
|
||||
'entity' => $blockClassNameDetails->getFullName(),
|
||||
'template' => $templatePath,
|
||||
'label' => Str::asHumanWords($blockClassNameDetails->getShortName())
|
||||
];
|
||||
|
||||
$blockPath = $generator->generateController(
|
||||
$blockClassNameDetails->getFullName(),
|
||||
__DIR__.'/../Resources/maker/builder/Block.tpl.php',
|
||||
$options
|
||||
);
|
||||
|
||||
$generator->writeChanges();
|
||||
$realTemplatePath = 'templates/'.$templatePath;
|
||||
|
||||
$filesystem = new Filesystem();
|
||||
|
||||
if (!$filesystem->exists($templatePath)) {
|
||||
$filesystem->mkdir(dirname($realTemplatePath));
|
||||
$filesystem->dumpFile($realTemplatePath, $this->getTemplate());
|
||||
|
||||
$io->comment(sprintf('<fg=blue>created</>: %s', $realTemplatePath));
|
||||
}
|
||||
|
||||
$this->writeSuccessMessage($io);
|
||||
}
|
||||
|
||||
protected function getTemplate(): string
|
||||
{
|
||||
return <<< EOF
|
||||
<div id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
EOF;
|
||||
}
|
||||
|
||||
public function configureDependencies(DependencyBuilder $dependencies)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -149,6 +149,7 @@ EOF
|
|||
'textarea' => null,
|
||||
'choice' => 'BlockEntity\\ChoiceBlock::class',
|
||||
'collection' => 'BlockEntity\\CollectionBlock::class',
|
||||
'builder' => 'BlockEntity\\BuilderBlock::class',
|
||||
'editor_js_textarea' => null,
|
||||
'file' => 'BlockEntity\\FileBlock::class',
|
||||
'file_picker' => null,
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace App\Core;
|
||||
|
||||
if (!defined('MURPH_VERSION')) {
|
||||
define('MURPH_VERSION', 'v1.23.0');
|
||||
define('MURPH_VERSION', 'v1.25.1');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -744,11 +744,134 @@ label.required::after {
|
|||
background: map-get($theme-colors, 'dark-blue');
|
||||
}
|
||||
|
||||
.tox.tox-silver-sink.tox-tinymce-aux {
|
||||
.tox {
|
||||
&.tox-silver-sink.tox-tinymce-aux {
|
||||
z-index: 3000 !important;
|
||||
}
|
||||
|
||||
&.tox-tinymce {
|
||||
border-color: $input-border-color;
|
||||
border-radius: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.field-boolean {
|
||||
color: #49555b;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.builder-widget {
|
||||
.block {
|
||||
border: 1px solid rgba(map-get($theme-colors, 'dark-blue'), 0.3);
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
margin-bottom: 10px;
|
||||
background: rgba(map-get($theme-colors, 'dark-blue'), 0.02);
|
||||
}
|
||||
|
||||
> .block {
|
||||
border: 1px solid map-get($theme-colors, 'dark-blue');
|
||||
}
|
||||
|
||||
.block-header {
|
||||
.block-header-item {
|
||||
font-size: 12px;
|
||||
display: inline-block;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
margin-right: 2px;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
$block-colors: #E183F5 #E3F7C6 #82DDF5 #F5BA82 #A088A6;
|
||||
$block-colors-length: length($block-colors);
|
||||
|
||||
.block .block-icon {
|
||||
> * {
|
||||
display: inline-block;
|
||||
margin-right: 3px;
|
||||
}
|
||||
}
|
||||
|
||||
@for $i from 1 through 100 {
|
||||
$block-color-index: ($block-colors-length + $i) % $block-colors-length + 1;
|
||||
|
||||
.block-depth-#{$i} {
|
||||
.block-label {
|
||||
background: nth($block-colors, $block-color-index);
|
||||
border: 1px solid darken(nth($block-colors, $block-color-index), 50%);
|
||||
color: darken(nth($block-colors, $block-color-index), 50%);
|
||||
}
|
||||
|
||||
.builder-add .btn {
|
||||
background: nth($block-colors, $block-color-index);
|
||||
border: 1px solid darken(nth($block-colors, $block-color-index), 50%);
|
||||
color: darken(nth($block-colors, $block-color-index), 50%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.builder-add {
|
||||
width: 100%;
|
||||
|
||||
&-top {
|
||||
margin-top: 7px;
|
||||
}
|
||||
|
||||
.btn {
|
||||
font-size: 12px;
|
||||
line-height: 14px;
|
||||
padding: 3px 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-root > .container .builder-add {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.block-settings {
|
||||
padding: 4px;
|
||||
margin-top: 10px;
|
||||
margin-bottom: 5px;
|
||||
|
||||
.form-control {
|
||||
margin-top: 0.5rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
.block .block {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.block-id {
|
||||
font-size: 12px;
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.block-show-dropzone {
|
||||
.block-dropzone {
|
||||
min-height: 40px;
|
||||
}
|
||||
}
|
||||
|
||||
.block-preview {
|
||||
white-space: nowrap;
|
||||
max-width: 30%;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.builder-code-editor {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
background: none;
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
|
||||
textarea {
|
||||
font-family: Monospace;
|
||||
min-height: 50vh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,3 +29,4 @@ require('./modules/file-picker.js')()
|
|||
require('./modules/analytics.js')()
|
||||
require('./modules/page.js')()
|
||||
require('./modules/node.js')()
|
||||
require('./modules/builder-block.js')()
|
||||
|
|
|
@ -0,0 +1,181 @@
|
|||
<template>
|
||||
<div
|
||||
class="block block-root"
|
||||
v-if="Object.keys(widgets).length && value !== null"
|
||||
>
|
||||
<div class="container">
|
||||
<BuilderBlockCreate
|
||||
:container="value"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="[]"
|
||||
v-if="value.length > 0"
|
||||
position="top"
|
||||
/>
|
||||
</div>
|
||||
<Draggable
|
||||
v-model="value"
|
||||
:key="blockKey"
|
||||
:animation="200"
|
||||
group="children"
|
||||
ghost-class="ghost"
|
||||
@start="dragStart"
|
||||
@end="dragEnd"
|
||||
handle=".dragger"
|
||||
:class="{'block-show-dropzone': showDragDrop}"
|
||||
>
|
||||
<BuilderBlockItem
|
||||
v-for="(block, key) in value"
|
||||
:key="block.id + '-' + key"
|
||||
:item="block"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:depth="1"
|
||||
@remove-item="removeBlock(key)"
|
||||
@drag-start="dragStart"
|
||||
@drag-end="dragEnd"
|
||||
/>
|
||||
<div class="container">
|
||||
<div class="d-flex justify-content-between">
|
||||
<BuilderBlockCreate
|
||||
:container="value"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="[]"
|
||||
position="bottom"
|
||||
/>
|
||||
<div>
|
||||
<BuilderBlockCodeEditor
|
||||
ref="dialog"
|
||||
:value="value"
|
||||
:widgets="widgets"
|
||||
@update="codeUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<textarea :name="name" class="d-none">{{ toJson(value) }}</textarea>
|
||||
</Draggable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BuilderBlockItem from './BuilderBlockItem'
|
||||
import BuilderBlockCodeEditor from './BuilderBlockCodeEditor'
|
||||
import BuilderBlockCreate from './BuilderBlockCreate'
|
||||
import Routing from '../../../../../../../../../friendsofsymfony/jsrouting-bundle/Resources/public/js/router.min.js'
|
||||
import Draggable from 'vuedraggable'
|
||||
|
||||
const axios = require('axios').default
|
||||
const routes = require('../../../../../../../../../../public/js/fos_js_routes.json')
|
||||
Routing.setRoutingData(routes)
|
||||
|
||||
export default {
|
||||
name: 'BuilderBlock',
|
||||
components: {
|
||||
BuilderBlockItem,
|
||||
BuilderBlockCreate,
|
||||
Draggable,
|
||||
BuilderBlockCodeEditor,
|
||||
},
|
||||
props: {
|
||||
id: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
initialValue: {
|
||||
type: Array,
|
||||
required: false,
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
value: null,
|
||||
nextValue: null,
|
||||
widgets: {},
|
||||
openedBlocks: {},
|
||||
blockKey: 0,
|
||||
showDragDrop: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toJson(value) {
|
||||
return JSON.stringify(value)
|
||||
},
|
||||
triggerBuilderBlockEvent() {
|
||||
document.querySelector('body').dispatchEvent(new Event('builder_block.update'))
|
||||
},
|
||||
codeUpdate(nextValue) {
|
||||
this.value = nextValue
|
||||
},
|
||||
removeBlock(key) {
|
||||
let newValue = []
|
||||
|
||||
this.value.forEach((v, k) => {
|
||||
if (k !== key) {
|
||||
newValue.push(v)
|
||||
}
|
||||
})
|
||||
|
||||
this.value = newValue
|
||||
|
||||
++this.blockKey
|
||||
},
|
||||
dragStart() {
|
||||
this.showDragDrop = true
|
||||
},
|
||||
dragEnd() {
|
||||
this.showDragDrop = false
|
||||
|
||||
++this.blockKey
|
||||
},
|
||||
fixSettings(data) {
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach((value, key) => {
|
||||
data[key] = this.fixSettings(value)
|
||||
})
|
||||
} else {
|
||||
const widget = this.widgets[data.widget]
|
||||
|
||||
if (!widget) {
|
||||
return data
|
||||
}
|
||||
|
||||
const nextSettings = {}
|
||||
|
||||
for (let setting in widget.settings) {
|
||||
if (data.settings.hasOwnProperty(setting)) {
|
||||
nextSettings[setting] = data.settings[setting]
|
||||
} else {
|
||||
nextSettings[setting] = widget.settings[setting].default
|
||||
}
|
||||
}
|
||||
|
||||
data.settings = nextSettings
|
||||
data.children = this.fixSettings(data.children)
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
const that = this
|
||||
|
||||
axios.get(Routing.generate('admin_editor_builder_block_widgets'))
|
||||
.then((response) => {
|
||||
that.widgets = response.data
|
||||
that.value = that.fixSettings(that.initialValue)
|
||||
})
|
||||
},
|
||||
created() {
|
||||
this.triggerBuilderBlockEvent()
|
||||
},
|
||||
updated() {
|
||||
this.triggerBuilderBlockEvent()
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,163 @@
|
|||
<template>
|
||||
<div>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm"
|
||||
v-on:click="open"
|
||||
>
|
||||
<i class="fas fa-code"></i>
|
||||
</button>
|
||||
<dialog ref="dialog" class="modal-dialog modal-dialog-large builder-code-editor">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title">Code editor</h5>
|
||||
<button
|
||||
type="button"
|
||||
class="close"
|
||||
v-on:click="close"
|
||||
>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="form-group">
|
||||
<textarea
|
||||
class="form-control"
|
||||
rows="10"
|
||||
ref="codeEditor"
|
||||
v-model="nextValue"
|
||||
>
|
||||
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-secondary"
|
||||
v-on:click="close"
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
v-on:click="checkAndSaveNextValue"
|
||||
>
|
||||
Save
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'BuilderBlockCodeEditor',
|
||||
props: {
|
||||
value: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
widgets: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
nextValue: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toJson(value) {
|
||||
return JSON.stringify(value, null, 2)
|
||||
},
|
||||
open() {
|
||||
this.nextValue = this.toJson(this.value)
|
||||
this.$refs.dialog.showModal()
|
||||
},
|
||||
close() {
|
||||
this.$refs.codeEditor.classList.toggle('is-invalid', false)
|
||||
this.$refs.dialog.close()
|
||||
},
|
||||
isNextValueItemValueValid(item) {
|
||||
const hasId = typeof item.id === 'string'
|
||||
const hasWidget = typeof item.widget === 'string' && this.widgets[item.widget]
|
||||
const hasSettings = typeof item.settings === 'object'
|
||||
const hasChildren = Array.isArray(item.children)
|
||||
|
||||
if (!hasId || !hasWidget || !hasSettings || !hasChildren) {
|
||||
return false
|
||||
}
|
||||
|
||||
for (let child of item.children) {
|
||||
if (!this.isNextValueItemValueValid(child)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
},
|
||||
updateNextValueRecursiveIds(data) {
|
||||
if (Array.isArray(data)) {
|
||||
data.forEach((value, key) => {
|
||||
data[key] = this.updateNextValueRecursiveIds(value)
|
||||
})
|
||||
} else {
|
||||
data.id = this.makeId()
|
||||
data.children = this.updateNextValueRecursiveIds(data.children)
|
||||
}
|
||||
|
||||
return data
|
||||
},
|
||||
checkAndSaveNextValue() {
|
||||
this.$refs.codeEditor.classList.toggle('is-invalid', false)
|
||||
let hasError = false
|
||||
|
||||
try {
|
||||
let data = JSON.parse(this.nextValue)
|
||||
|
||||
if (!Array.isArray(data)) {
|
||||
hasError = true
|
||||
} else {
|
||||
for (let item of data) {
|
||||
if (!this.isNextValueItemValueValid(item)) {
|
||||
hasError = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasError) {
|
||||
this.$emit('update', this.updateNextValueRecursiveIds(data))
|
||||
this.close()
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
hasError = true
|
||||
}
|
||||
|
||||
return this.$refs.codeEditor.classList.toggle('is-invalid', hasError)
|
||||
},
|
||||
makeId() {
|
||||
let result = ''
|
||||
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
const charactersLength = characters.length
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength))
|
||||
}
|
||||
|
||||
return `block-${result}`
|
||||
},
|
||||
},
|
||||
components: {
|
||||
},
|
||||
mounted() {
|
||||
},
|
||||
created() {
|
||||
},
|
||||
updated() {
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,205 @@
|
|||
<style scoped>
|
||||
.builder-block-picker {
|
||||
padding: 8px;
|
||||
border: 1px solid #333;
|
||||
border-radius: 4px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.builder-block-picker-menu {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.builder-block-picker-widgets {
|
||||
width: calc(100% - 150px - 10px);
|
||||
padding-left: 5px;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
cursor: pointer;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.widget-icon {
|
||||
margin-right: 3px;
|
||||
}
|
||||
|
||||
.widget {
|
||||
background: #fff;
|
||||
padding: 10px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
margin-right: 7px;
|
||||
margin-bottom: 9px;
|
||||
border: 1px solid #b4b4b4;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.widget:hover {
|
||||
background: #eee;
|
||||
border: 1px solid #1e2430;
|
||||
}
|
||||
|
||||
.search {
|
||||
max-width: 300px;
|
||||
}
|
||||
</style>
|
||||
|
||||
<template>
|
||||
<div class="builder-add" :class="{'builder-add-top': position === 'top'}">
|
||||
<button type="button" class="btn btn-secondary" v-on:click="togglePicker">
|
||||
<span class="fa fa-plus"></span>
|
||||
</button>
|
||||
|
||||
<div class="builder-block-picker mt-2 row" :class="{'d-none': !showPicker}">
|
||||
<div class="col-auto builder-block-picker-menu">
|
||||
<ul class="nav nav-pills pl-0">
|
||||
<li
|
||||
v-for="(category, key) in categories()"
|
||||
v-if="Object.keys(category.widgets).length"
|
||||
class="nav-item d-block"
|
||||
>
|
||||
<a
|
||||
class="nav-link d-block mb-1"
|
||||
:class="{'active': activeCategory == key}"
|
||||
v-on:click="activeCategory = key"
|
||||
>
|
||||
{{ category.label }}
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div
|
||||
v-for="(category, key) in categories()"
|
||||
v-if="Object.keys(category.widgets).length"
|
||||
class="col-auto builder-block-picker-widgets"
|
||||
:class="{'d-none': activeCategory !== key}"
|
||||
>
|
||||
<div class="row">
|
||||
<div class="col-12 mb-4">
|
||||
<input v-model="search" placeholder="Type to search..." class="form-control search">
|
||||
</div>
|
||||
<div
|
||||
v-for="(widget, name) in category.widgets"
|
||||
v-on:click="add(name, widget)"
|
||||
v-if="matchSearch(widget.label) || matchSearch(name)"
|
||||
class="widget col-auto"
|
||||
>
|
||||
<span class="widget-icon" v-if="widget.icon" v-html="widget.icon"></span>
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
export default {
|
||||
name: 'BuilderBlockCreate',
|
||||
props: {
|
||||
container: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
widgets: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
allowedWidgets: {
|
||||
type: Array,
|
||||
required: true
|
||||
},
|
||||
openedBlocks: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
position: {
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
showPicker: false,
|
||||
activeCategory: 'all',
|
||||
search: '',
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
add(name, widget) {
|
||||
let settings = {}
|
||||
|
||||
for (let i in widget.settings) {
|
||||
settings[i] = widget.settings[i].default
|
||||
}
|
||||
|
||||
const block = {
|
||||
id: this.makeId(),
|
||||
widget: name,
|
||||
settings,
|
||||
children: [],
|
||||
}
|
||||
|
||||
if (this.position === 'bottom') {
|
||||
this.container.push(block)
|
||||
} else {
|
||||
this.container.unshift(block)
|
||||
}
|
||||
|
||||
this.$emit('updateContainer', this.container)
|
||||
this.openedBlocks[block.id] = true
|
||||
this.togglePicker()
|
||||
},
|
||||
makeId() {
|
||||
let result = ''
|
||||
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||||
const charactersLength = characters.length
|
||||
|
||||
for (let i = 0; i < 7; i++) {
|
||||
result += characters.charAt(Math.floor(Math.random() * charactersLength))
|
||||
}
|
||||
|
||||
return `block-${result}`
|
||||
},
|
||||
matchSearch(name) {
|
||||
if (!this.search.trim().length) {
|
||||
return true
|
||||
}
|
||||
|
||||
return name.toLowerCase().includes(this.search.toLowerCase())
|
||||
},
|
||||
togglePicker() {
|
||||
this.showPicker = !this.showPicker
|
||||
},
|
||||
categories() {
|
||||
let items = {
|
||||
all: {label: 'All', widgets: {}},
|
||||
}
|
||||
|
||||
for (let widgetName in this.widgets) {
|
||||
let value = this.widgets[widgetName]
|
||||
|
||||
if (!value.category) {
|
||||
value.category = 'all'
|
||||
}
|
||||
|
||||
if (typeof items[value.category] === 'undefined') {
|
||||
items[value.category] = {
|
||||
label: value.category,
|
||||
widgets: {},
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.allowedWidgets.length || this.allowedWidgets.includes(widgetName)) {
|
||||
items[value.category].widgets[widgetName] = value
|
||||
items['all'].widgets[widgetName] = value
|
||||
}
|
||||
}
|
||||
|
||||
return items
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,212 @@
|
|||
<template>
|
||||
<div
|
||||
class="block"
|
||||
:class="'block-depth-' + depth"
|
||||
v-if="widget"
|
||||
:key="blockKey"
|
||||
>
|
||||
<div class="block-header d-flex justify-content-between">
|
||||
<div>
|
||||
<div
|
||||
class="block-header-item block-label"
|
||||
:title="item.widget"
|
||||
>
|
||||
<span
|
||||
class="block-icon"
|
||||
v-if="widget.icon"
|
||||
v-html="widget.icon"
|
||||
>
|
||||
</span>
|
||||
|
||||
{{ widget.label }}
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm btn-outline-secondary"
|
||||
v-on:click="toggleSettings"
|
||||
v-if="Object.keys(widget.settings).length"
|
||||
>
|
||||
<span class="fa fa-cog"></span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm btn-outline-secondary dragger"
|
||||
>
|
||||
<span class="fa fa-arrows-alt dragger"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="widget.preview && typeof item.settings[widget.preview] == 'string'"
|
||||
class="block-preview"
|
||||
>
|
||||
{{ truncate(item.settings[widget.preview]) }}
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<span class="block-id">
|
||||
{{ item.id }}
|
||||
</span>
|
||||
<button
|
||||
type="button"
|
||||
class="block-header-item btn btn-sm text-white bg-danger"
|
||||
v-on:click="removeMe(item)"
|
||||
>
|
||||
<span class="fa fa-trash dragger"></span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="block-settings" v-if="Object.keys(widget.settings).length" :class="{'d-none': !showSettings}">
|
||||
<div class="row">
|
||||
<BuilderBlockSetting
|
||||
class="mb-0"
|
||||
v-for="(params, setting) in widget.settings"
|
||||
:key="item.id + '-' + setting"
|
||||
:class="widget.class"
|
||||
:item="item"
|
||||
:params="params"
|
||||
:setting="setting"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="widget.isContainer" class="container">
|
||||
<BuilderBlockCreate
|
||||
:container="item.children"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="widget.widgets"
|
||||
v-if="item.children.length > 0"
|
||||
position="top"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Draggable
|
||||
v-if="widget.isContainer"
|
||||
v-model="item.children"
|
||||
ghost-class="ghost"
|
||||
group="children"
|
||||
@start="dragStart"
|
||||
@end="dragEnd"
|
||||
:animation="200"
|
||||
handle=".dragger"
|
||||
class="block-dropzone"
|
||||
>
|
||||
<BuilderBlockItem
|
||||
v-if="item.children !== null && item.children.length > 0"
|
||||
v-for="(child, key) in item.children"
|
||||
:key="child.id"
|
||||
:item="child"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:depth="depth + 1"
|
||||
@remove-item="removeBlock(key)"
|
||||
@drag-start="dragStart"
|
||||
@drag-end="dragEnd"
|
||||
/>
|
||||
</Draggable>
|
||||
|
||||
<div v-if="widget.isContainer" class="container">
|
||||
<div class="d-flex justify-content-between">
|
||||
<BuilderBlockCreate
|
||||
:container="item.children"
|
||||
:widgets="widgets"
|
||||
:openedBlocks="openedBlocks"
|
||||
:allowedWidgets="widget.widgets"
|
||||
position="bottom"
|
||||
/>
|
||||
<BuilderBlockCodeEditor
|
||||
ref="dialog"
|
||||
:value="item.children"
|
||||
:widgets="widgets"
|
||||
@update="codeUpdate"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import BuilderBlockCreate from './BuilderBlockCreate'
|
||||
import BuilderBlockCodeEditor from './BuilderBlockCodeEditor'
|
||||
import BuilderBlockSetting from './BuilderBlockSetting'
|
||||
import Draggable from 'vuedraggable'
|
||||
|
||||
export default {
|
||||
name: 'BuilderBlockItem',
|
||||
components: {
|
||||
BuilderBlockCreate,
|
||||
BuilderBlockSetting,
|
||||
BuilderBlockCodeEditor,
|
||||
Draggable,
|
||||
},
|
||||
props: {
|
||||
widgets: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
item: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
openedBlocks: {
|
||||
type: Object,
|
||||
required: true
|
||||
},
|
||||
depth: {
|
||||
type: Number,
|
||||
required: true
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
widget: null,
|
||||
showSettings: this.openedBlocks[this.item.id] === true,
|
||||
blockKey: 0,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleSettings() {
|
||||
this.openedBlocks[this.item.id] = !this.openedBlocks[this.item.id]
|
||||
this.showSettings = !this.showSettings
|
||||
},
|
||||
truncate(value) {
|
||||
return value.replace(/(<([^>]+)>)/ig, '').trim()
|
||||
},
|
||||
removeMe() {
|
||||
this.$emit('remove-item')
|
||||
},
|
||||
codeUpdate(nextValue) {
|
||||
this.item.children = nextValue
|
||||
},
|
||||
removeBlock(key) {
|
||||
let children = []
|
||||
|
||||
this.item.children.forEach((v, k) => {
|
||||
if (k !== key) {
|
||||
children.push(v)
|
||||
}
|
||||
})
|
||||
|
||||
this.item.children = children
|
||||
++this.blockKey
|
||||
},
|
||||
dragStart() {
|
||||
this.$emit('drag-start')
|
||||
},
|
||||
dragEnd() {
|
||||
this.$emit('drag-end')
|
||||
++this.blockKey
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.widget = this.widgets[this.item.widget]
|
||||
},
|
||||
updated() {
|
||||
document.querySelector('body').dispatchEvent(new Event('builder_block.update'))
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,59 @@
|
|||
<template>
|
||||
<label class="form-group mb-2">
|
||||
<span v-if="params.label && params.type !== 'checkbox'" v-text="params.label"></span>
|
||||
|
||||
<input
|
||||
v-if="['number', 'checkbox', 'text'].includes(params.type)"
|
||||
v-model="item.settings[setting]"
|
||||
v-bind="params.attr"
|
||||
:type="params.type"
|
||||
:class="{'form-control': params.type !== 'checkbox'}"
|
||||
/>
|
||||
|
||||
<span v-if="params.label && params.type == 'checkbox'" v-text="params.label"></span>
|
||||
|
||||
<textarea
|
||||
v-if="params.type == 'textarea'"
|
||||
v-model="item.settings[setting]"
|
||||
v-bind="params.attr"
|
||||
class="form-control"
|
||||
></textarea>
|
||||
|
||||
<select
|
||||
v-if="params.type == 'select'"
|
||||
v-model="item.settings[setting]"
|
||||
v-bind="params.attr"
|
||||
class="form-control"
|
||||
>
|
||||
<option :value="v.value" v-for="(v, k) in params.options" :key="k">
|
||||
{{ v.text }}
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'BuilderBlockSetting',
|
||||
props: {
|
||||
item: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
params: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
setting: {
|
||||
type: String,
|
||||
required: true,
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
label > span {
|
||||
margin-bottom: 3px;
|
||||
}
|
||||
</style>
|
|
@ -201,8 +201,8 @@ import Routing from '../../../../../../../../../friendsofsymfony/jsrouting-bundl
|
|||
import FileIcon from './FileIcon'
|
||||
|
||||
const axios = require('axios').default
|
||||
const $ = require('jquery')
|
||||
const routes = require('../../../../../../../../../../public/js/fos_js_routes.json')
|
||||
const $ = require('jquery')
|
||||
|
||||
Routing.setRoutingData(routes)
|
||||
|
||||
|
|
28
src/core/Resources/assets/js/modules/builder-block.js
Normal file
28
src/core/Resources/assets/js/modules/builder-block.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const Vue = require('vue').default
|
||||
|
||||
const BuilderBlock = require('../components/builder-block/BuilderBlock').default
|
||||
|
||||
module.exports = () => {
|
||||
const wrappers = document.querySelectorAll('.builder-widget')
|
||||
|
||||
wrappers.forEach((wrapper) => {
|
||||
const component = wrapper.querySelector('.builder-widget-component')
|
||||
|
||||
return new Vue({
|
||||
el: component,
|
||||
template: `<BuilderBlock
|
||||
:initialValue="value"
|
||||
name="${component.getAttribute('data-name')}"
|
||||
id="${component.getAttribute('data-id')}"
|
||||
/>`,
|
||||
data() {
|
||||
return {
|
||||
value: JSON.parse(component.getAttribute('data-value'))
|
||||
}
|
||||
},
|
||||
components: {
|
||||
BuilderBlock
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
|
@ -53,7 +53,7 @@ const fileManagerBrowser = function (callback) {
|
|||
})
|
||||
}
|
||||
|
||||
if (typeof window.tinymce !== 'undefined') {
|
||||
const createTinymceConfig = function () {
|
||||
window.tinymce.murph = window.tinymce.murph || {}
|
||||
window.tinymce.murph.selector = window.tinymce.murph.selector || '*[data-tinymce]'
|
||||
window.tinymce.murph.configurationBase = window.tinymce.murph.configurationBase || {
|
||||
|
@ -74,12 +74,15 @@ if (typeof window.tinymce !== 'undefined') {
|
|||
})
|
||||
|
||||
editor.on('Change', () => {
|
||||
editor.save();
|
||||
editor.getElement().dispatchEvent(new Event('input'));
|
||||
window.tinymce.triggerSave(false, true)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
window.tinymce.murph.modes = window.tinymce.murph.modes || {}
|
||||
window.tinymceModes = window.tinymceModes || {}
|
||||
|
||||
window.tinymce.murph.modes.default = window.tinymce.murph.modes.default || {
|
||||
plugins: 'print preview importcss searchreplace visualblocks visualchars fullscreen template table charmap hr pagebreak nonbreaking toc insertdatetime advlist lists wordcount textpattern noneditable help charmap quickbars link image code autoresize',
|
||||
|
@ -95,6 +98,11 @@ if (typeof window.tinymce !== 'undefined') {
|
|||
toolbar: 'undo redo | bold italic underline'
|
||||
}
|
||||
|
||||
window.tinymce.murph.modes = {
|
||||
...window.tinymce.murph.modes,
|
||||
...window.tinymceModes
|
||||
}
|
||||
|
||||
tinymce.addI18n('fr_FR', {
|
||||
Redo: 'R\u00e9tablir',
|
||||
Undo: 'Annuler',
|
||||
|
@ -612,17 +620,21 @@ const doInitEditor = () => {
|
|||
}
|
||||
|
||||
module.exports = function () {
|
||||
if (typeof tinymce === 'undefined') {
|
||||
return
|
||||
}
|
||||
document.querySelector('body').addEventListener('builder_block.update', () => {
|
||||
window.setTimeout(() => {
|
||||
createTinymceConfig()
|
||||
doInitEditor()
|
||||
}, 500)
|
||||
})
|
||||
|
||||
$(() => {
|
||||
createTinymceConfig()
|
||||
doInitEditor()
|
||||
|
||||
const observer = new MutationObserver(doInitEditor)
|
||||
const config = { attributes: false, childList: true, subtree: true }
|
||||
observer.observe(document.querySelector('body'), config)
|
||||
|
||||
$(() => {
|
||||
doInitEditor()
|
||||
|
||||
$('body').on('hidden.bs.modal', '.modal', (e) => {
|
||||
if (!$('.tox-dialog').length) {
|
||||
$(e.target).find('.tox-tinymce').each(() => {
|
||||
|
|
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
38
src/core/Resources/maker/builder/Block.tpl.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php echo "<?php\n"; ?>
|
||||
|
||||
namespace <?php echo $namespace; ?>;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlock;
|
||||
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
|
||||
|
||||
#[AutoconfigureTag('builder_block.widget')]
|
||||
class <?php echo $class_name; ?> extends BuilderBlock
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this
|
||||
->setName('<?php echo $class_name; ?>')
|
||||
->setCategory('Custom')
|
||||
->setTemplate('<?php echo $template; ?>')
|
||||
->setLabel('<?php echo $label; ?>')
|
||||
// ->setOrder(1)
|
||||
// ->setIsContainer(false)
|
||||
// ->setIcon('<i class="fas fa-pencil-alt"></i>')
|
||||
// ->setClass('col-md-12')
|
||||
// ->addSetting(name: 'value1', label: 'Text', type: 'text', attributes: [], default: '')
|
||||
// ->addSetting(name: 'value2', label: 'Checkbox', type: 'checkbox', attributes: [], default: true)
|
||||
// ->addSetting(name: 'value2', label: 'Number', type: 'checkbox', attributes: [], default: true)
|
||||
// ->addSetting(name: 'value3', label: 'Textarea', type: 'textarea', attributes: [], default: '')
|
||||
// ->addSetting(name: 'value4', label: 'Choice', type: 'select', attributes: [], default: '', extraOptions: [
|
||||
// 'options' => [
|
||||
// ['text' => 'Choice 1', 'value' => 'choice1'],
|
||||
// ['text' => 'Choice 2', 'value' => 'choice2'],
|
||||
// ],
|
||||
// ])
|
||||
;
|
||||
}
|
||||
|
||||
public function buildVars(array $data, array $context)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -11,11 +11,11 @@ use <?php echo $entity; ?> as Entity;
|
|||
use <?php echo $factory; ?> as Factory;
|
||||
use <?php echo $form; ?> as Type;
|
||||
use <?php echo $repository_query; ?> as RepositoryQuery;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class <?php echo $class_name; ?> extends CrudController
|
||||
{
|
||||
|
|
|
@ -224,3 +224,14 @@
|
|||
"All roles": "Tous les rôles"
|
||||
"Enable A/B Testing": "Activer le test A/B"
|
||||
"Color": "Couleur"
|
||||
"Extra small": "Très petit"
|
||||
"Small": "Petit"
|
||||
"Medium": "Moyen"
|
||||
"Large": "Large"
|
||||
"Extra large": "Très large"
|
||||
"Level": "Niveau"
|
||||
"Insert line breaks": "Ajouter les retours chariot"
|
||||
'Allow HTML': "Autoriser l'HTML"
|
||||
"Custom class": "Classe personnalisée"
|
||||
"Editors": "Éditeurs"
|
||||
"All": "Tous"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<div class="alert {% if settings.level|default(null) %}alert-{{ settings.level }}{% endif %}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -0,0 +1,13 @@
|
|||
{% set sizes = {
|
||||
'col-': settings.size|default(null),
|
||||
'col-xs-': settings.sizeXs|default(null),
|
||||
'col-md-': settings.sizeMd|default(null),
|
||||
'col-lg-': settings.sizeLg|default(null),
|
||||
'col-xl-': settings.sizeXl|default(null),
|
||||
} %}
|
||||
|
||||
<div class="col {% for i, v in sizes%}{% if v|length %}{{ i }}{{ v }} {% endif %}{% endfor -%} {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -0,0 +1,5 @@
|
|||
<div class="container{% if settings.isFluid|default(false) %}-fluid{% endif %} {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -0,0 +1,5 @@
|
|||
<div class="row {{ settings.customClass|default(null) }}" id="{{ id }}">
|
||||
{% for item in children %}
|
||||
{{ item|block_to_html(context) }}
|
||||
{% endfor %}
|
||||
</div>
|
|
@ -0,0 +1,13 @@
|
|||
{%- if settings.nl2br|default(null) -%}
|
||||
{% if settings.allowHtml|default(null) %}
|
||||
{{- settings.value|default(null)|raw|nl2br -}}
|
||||
{%- else -%}
|
||||
{{- settings.value|default(null)|nl2br -}}
|
||||
{%- endif -%}
|
||||
{%- else -%}
|
||||
{% if settings.allowHtml|default(null) %}
|
||||
{{- settings.value|default(null)|raw -}}
|
||||
{%- else -%}
|
||||
{{- settings.value|default(null) -}}
|
||||
{%- endif -%}
|
||||
{% endif %}
|
|
@ -0,0 +1 @@
|
|||
{{ settings.value|default(null)|file_attributes|murph_url|raw }}
|
|
@ -197,6 +197,10 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
{% if splInfo.isFile and not isLocked %}
|
||||
<button type="submit" class="btn btn-primary" form="form-fm-attributes">{{ 'Save'|trans }}</button>
|
||||
{% endif %}
|
||||
|
||||
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ 'Close'|trans }}</button>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
|
|
@ -1,5 +1,19 @@
|
|||
{% extends 'bootstrap_4_layout.html.twig' %}
|
||||
|
||||
{% block builder_widget %}
|
||||
{% set row_attr = row_attr|merge({class: 'builder-widget ' ~ (row_attr.class ?? '')}) %}
|
||||
{% set value = value is iterable ? value|json_encode : value %}
|
||||
|
||||
{% if value == '' %}
|
||||
{% set value = '[]' %}
|
||||
{% endif %}
|
||||
|
||||
<div {% for attr, value in row_attr %}{{ attr }}="{{ value }}" {% endfor %}>
|
||||
<div class="builder-widget-component" data-value="{{ value }}" data-name="{{ full_name }}" data-id="{{ id }}">
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block grapesjs_widget %}
|
||||
<div class="gjs"></div>
|
||||
<div class="d-none">
|
||||
|
|
64
src/core/Twig/Extension/BuilderExtension.php
Normal file
64
src/core/Twig/Extension/BuilderExtension.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace App\Core\Twig\Extension;
|
||||
|
||||
use App\Core\BuilderBlock\BuilderBlockContainer;
|
||||
use Twig\Environment;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFilter;
|
||||
|
||||
class BuilderExtension extends AbstractExtension
|
||||
{
|
||||
public function __construct(protected Environment $twig, protected BuilderBlockContainer $container)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('block_to_html', [$this, 'buildHtml'], ['is_safe' => ['html']]),
|
||||
];
|
||||
}
|
||||
|
||||
public function buildHtml(null|array|string $data, array $context = []): ?string
|
||||
{
|
||||
if (null === $data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true);
|
||||
}
|
||||
|
||||
if (!is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($data['widget'])) {
|
||||
if (!$this->container->hasWidget($data['widget'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$widget = $this->container->getWidget($data['widget']);
|
||||
$widget->buildVars($data, $context);
|
||||
|
||||
return $this->twig->render($widget->getTemplate(), [
|
||||
'id' => $data['id'],
|
||||
'settings' => $data['settings'],
|
||||
'children' => $data['children'],
|
||||
'context' => $context,
|
||||
'vars' => $widget->getVars(),
|
||||
]);
|
||||
}
|
||||
|
||||
$render = '';
|
||||
foreach ($data as $item) {
|
||||
$render .= $this->buildHtml($item, $context);
|
||||
}
|
||||
|
||||
return $render;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue