Skip to content
Merged
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
23 changes: 23 additions & 0 deletions assets/scripts/admin/content-edit/preview-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ registerFeature('admin_content_edit_preview_section', _init);
*/
function _init() {
cmsEditListener('[data-section-preview-input]', 'change', showSectionPreview);
cmsEditListener('[data-section-widget]', 'change', showSectionNote);
}

/**
Expand All @@ -24,4 +25,26 @@ function showSectionPreview(inputElement, module, preview/*, form, event*/) {
let sectionPreview = inputElement.options[inputElement.selectedIndex].dataset.sectionPreview;
[...htmlTargetElements].forEach((htmlTargetElement) => htmlTargetElement.innerHTML = sectionPreview === undefined ? '' : sectionPreview);
filterCurrentFilterElements();
}

/**
* Shows a section preview
*
* The preview target element must have the "data-section-preview-target" attribute
* The select option must have the "data-section-preview-input"
* Both data attributes must have the same value (as identificator)
Comment thread
javihgil marked this conversation as resolved.
Comment thread
javihgil marked this conversation as resolved.
*/
function showSectionNote(inputElement, module, preview, form/*, event*/) {
let htmlTargetElements = form.querySelectorAll("[data-section-note-preview='" + inputElement.id + "']");
let sectionNote = inputElement.options[inputElement.selectedIndex].dataset.sectionNotes;

[...htmlTargetElements].forEach((htmlTargetElement) => {
if (sectionNote) {
htmlTargetElement.innerHTML = sectionNote;
htmlTargetElement.classList.remove('d-none');
} else {
htmlTargetElement.innerHTML = '';
htmlTargetElement.classList.add('d-none');
}
});
}
7 changes: 7 additions & 0 deletions cms/modules/section/form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
</div>
{{ sfs_cms_admin_module_accordion_block_end() }}

{% import '@SfsCms/macros/modules_edit.html.twig' as edit %}

{{ sfs_cms_admin_module_accordion_block_start(form, accordion, 'section', true) }}
<div class="col-12" data-section-message-container>
{{ form_row(form.section, {'attr': attr | merge({'data-section-message-select': ''})}) }}

<div class="alert alert-info mt-3" data-section-note-preview="{{ form.section.vars.id }}">
{{ form.section.vars.section_notes|raw }}
</div>

{{ form_row(form.mode, {'attr': attr | merge({'data-section-mode-message-select': ''})}) }}

<div class="alert alert-danger mt-3 d-none" role="alert" data-section-message-when data-section-when-section-draft
Expand Down
2 changes: 2 additions & 0 deletions config/doctrine-mapping/model/Section.orm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<option name="unsigned">true</option>
</options>
</field>

<field name="notes" column="notes" type="text" nullable="true"/>
</mapped-superclass>

</doctrine-mapping>
6 changes: 6 additions & 0 deletions src/Form/Admin/Section/SectionCreateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Locales;
Expand Down Expand Up @@ -63,5 +64,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'choices' => array_combine(array_map(fn ($lang) => Locales::getName($lang), $options['locales']), $options['locales']),
'default_value' => [$options['default_locale']],
]);

$builder->add('notes', TextareaType::class, [
'required' => false,
'help' => 'admin_sections.form.notes.help',
]);
}
}
6 changes: 6 additions & 0 deletions src/Form/Admin/Section/SectionUpdateForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Intl\Locales;
Expand Down Expand Up @@ -65,5 +66,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
'constraints' => new Count(['min' => 1]),
'default_value' => [$options['default_locale']],
]);

$builder->add('notes', TextareaType::class, [
'required' => false,
'help' => 'admin_sections.form.notes.help',
]);
}
}
3 changes: 3 additions & 0 deletions src/Form/Type/SectionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function configureOptions(OptionsResolver $resolver): void
}

$attr['data-section-preview'] = '';
$attr['data-section-notes'] = nl2br($section->getNotes());

foreach ($this->cmsConfig->getSites() as $site) {
foreach ($this->localeHelper->getEnabledLocales() as $locale) {
Expand All @@ -95,11 +96,13 @@ public function configureOptions(OptionsResolver $resolver): void
public function finishView(FormView $view, FormInterface $form, array $options): void
{
$view->vars['section_preview'] = '';
$view->vars['section_notes'] = '';

/** @var ChoiceView $choice */
foreach ($view->vars['choices'] as $choice) {
if ($view->vars['value'] == $choice->value) {
$view->vars['section_preview'] = $choice->attr['data-section-preview'];
$view->vars['section_notes'] = $choice->attr['data-section-notes'];
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions src/Migrations/Version20251015150528.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Softspring\CmsSectionsPlugin\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20251015150528 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add notes field to cms_section table';
}

public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE cms_section ADD notes LONGTEXT DEFAULT NULL');
}

public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE cms_section DROP notes');
}
}
12 changes: 12 additions & 0 deletions src/Model/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ abstract class Section implements SectionInterface

protected ?array $extraData = null;

protected ?string $notes = null;

public function __construct()
{
$this->versions = new ArrayCollection();
Expand Down Expand Up @@ -58,4 +60,14 @@ public function setExtra(string $key, mixed $value): void
}
$this->extraData[$key] = $value;
}

public function getNotes(): ?string
{
return $this->notes;
}

public function setNotes(?string $notes): void
{
$this->notes = $notes;
}
}
4 changes: 4 additions & 0 deletions src/Model/SectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public function setExtraData(?array $extraData): void;
public function getExtra(string $key, mixed $default = null): mixed;

public function setExtra(string $key, mixed $value): void;

public function getNotes(): ?string;

public function setNotes(?string $notes): void;
}
3 changes: 3 additions & 0 deletions translations/sfs_cms_admin.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ admin_sections:
ttl.label: "Cache time"
defaultLocale.label: "Default language"
locales.label: "Languages"
notes:
label: "Integration notes"
help: "This note is only for internal use, will be displayed when integrating sections in contents. (can contain HTML)"

version_form:
note.label: "Note"
Expand Down
3 changes: 3 additions & 0 deletions translations/sfs_cms_admin.es.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ admin_sections:
ttl.label: "Tiempo de cache"
defaultLocale.label: "Idioma por defecto"
locales.label: "Idiomas"
notes:
label: "Notas de integración"
help: "Esta nota es solo para uso interno, se mostrará al integrar secciones en contenidos. (puede contener HTML)"

version_form:
note.label: "Nota"
Expand Down