add blocks

This commit is contained in:
Simon Vieille 2024-05-13 13:58:07 +02:00
parent 48ca5a96e6
commit 857fcd9897
Signed by: deblan
GPG key ID: 579388D585F70417
5 changed files with 94 additions and 0 deletions

View 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])
;
}
}

View file

@ -0,0 +1,26 @@
<?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')
;
}
}

View file

@ -229,3 +229,6 @@
"Medium": "Moyen"
"Large": "Large"
"Extra large": "Très large"
"Level": "Niveau"
"Insert line breaks": "Ajouter les retours chariot"
'Allow HTML': "Autoriser l'HTML"

View file

@ -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 }}
{% endfor %}
</div>

View file

@ -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 %}