diff --git a/assets/controllers/elements/structural_entity_select_controller.js b/assets/controllers/elements/structural_entity_select_controller.js
index 27425101..077f8417 100644
--- a/assets/controllers/elements/structural_entity_select_controller.js
+++ b/assets/controllers/elements/structural_entity_select_controller.js
@@ -34,21 +34,29 @@ export default class extends Controller {
this._emptyMessage = this.element.getAttribute("data-empty-message") ?? "";
const allowAdd = this.element.getAttribute("data-allow-add") === "true";
+ const addHint = this.element.getAttribute("data-add-hint") ?? "";
let settings = {
allowEmptyOption: true,
selectOnTab: true,
maxOptions: null,
create: allowAdd,
+ createFilter: /\D/, //Must contain a non-digit character, otherwise they would be recognized as DB ID
searchField: [
{field: "text", weight : 2},
{field: "parent", weight : 0.5},
+ {field: "path", weight : 1.0},
],
render: {
item: this.renderItem.bind(this),
option: this.renderOption.bind(this),
+ option_create: function(data, escape) {
+ return '
Add ' + escape(data.input) + '… ' +
+ '(' + addHint +')' +
+ '
';
+ },
}
};
diff --git a/src/Form/Type/CurrencyEntityType.php b/src/Form/Type/CurrencyEntityType.php
index 59096302..08bc17ea 100644
--- a/src/Form/Type/CurrencyEntityType.php
+++ b/src/Form/Type/CurrencyEntityType.php
@@ -32,6 +32,7 @@ use RuntimeException;
use Symfony\Component\Intl\Currencies;
use Symfony\Component\OptionsResolver\Options;
use Symfony\Component\OptionsResolver\OptionsResolver;
+use Symfony\Contracts\Translation\TranslatorInterface;
/**
* An entity to select a currency shortly
@@ -40,9 +41,9 @@ class CurrencyEntityType extends StructuralEntityType
{
protected ?string $base_currency;
- public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, AttachmentURLGenerator $attachmentURLGenerator, ?string $base_currency)
+ public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, AttachmentURLGenerator $attachmentURLGenerator, TranslatorInterface $translator, ?string $base_currency)
{
- parent::__construct($em, $builder, $attachmentURLGenerator);
+ parent::__construct($em, $builder, $attachmentURLGenerator, $translator);
$this->base_currency = $base_currency;
}
diff --git a/src/Form/Type/StructuralEntityType.php b/src/Form/Type/StructuralEntityType.php
index 1b46ab14..42f3686b 100644
--- a/src/Form/Type/StructuralEntityType.php
+++ b/src/Form/Type/StructuralEntityType.php
@@ -44,6 +44,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\AtLeastOneOf;
use Symfony\Component\Validator\Constraints\IsNull;
use Symfony\Component\Validator\Constraints\Valid;
+use Symfony\Contracts\Translation\TranslatorInterface;
/**
* This class provides a choice form type similar to EntityType, with the difference, that the tree structure
@@ -53,17 +54,19 @@ class StructuralEntityType extends AbstractType
{
protected EntityManagerInterface $em;
protected AttachmentURLGenerator $attachmentURLGenerator;
+ protected TranslatorInterface $translator;
/**
* @var NodesListBuilder
*/
protected $builder;
- public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, AttachmentURLGenerator $attachmentURLGenerator)
+ public function __construct(EntityManagerInterface $em, NodesListBuilder $builder, AttachmentURLGenerator $attachmentURLGenerator, TranslatorInterface $translator)
{
$this->em = $em;
$this->builder = $builder;
$this->attachmentURLGenerator = $attachmentURLGenerator;
+ $this->translator = $translator;
}
public function buildForm(FormBuilderInterface $builder, array $options): void
@@ -85,21 +88,6 @@ class StructuralEntityType extends AbstractType
}
});
- /* $builder->addEventListener(FormEvents::POST_SUBMIT, function (PostSubmitEvent $event) {
- $name = $event->getForm()->getConfig()->getName();
- $data = $event->getForm()->getData();
-
- if ($event->getForm()->getParent() === null) {
- return;
- }
-
- $event->getForm()->getParent()->add($name, static::class, $event->getForm()->getConfig()->getOptions());
- $new_form = $event->getForm()->getParent()->get($name);
- $new_form->setData($data);
- });*/
-
-
-
$builder->addModelTransformer(new CallbackTransformer(
function ($value) use ($options) {
return $this->modelTransform($value, $options);
@@ -145,7 +133,7 @@ class StructuralEntityType extends AbstractType
{
//Show entities that are not added to DB yet separately from other entities
if ($element->getID() === null) {
- return 'New (not added to DB yet)';
+ return $this->translator->trans('entity.select.group.new_not_added_to_DB');
}
return null;
@@ -166,10 +154,11 @@ class StructuralEntityType extends AbstractType
$resolver->setDefault('controller', 'elements--structural-entity-select');
- $resolver->setDefault('attr', static function (Options $options) {
+ $resolver->setDefault('attr', function (Options $options) {
$tmp = [
'data-controller' => $options['controller'],
'data-allow-add' => $options['allow_add'] ? 'true' : 'false',
+ 'data-add-hint' => $this->translator->trans('entity.select.add_hint'),
];
if ($options['empty_message']) {
$tmp['data-empty-message'] = $options['empty_message'];
@@ -236,6 +225,7 @@ class StructuralEntityType extends AbstractType
$tmp += [
'data-level' => $level,
'data-parent' => $choice->getParent() ? $choice->getParent()->getFullPath() : null,
+ 'data-path' => $choice->getFullPath('->'),
'data-image' => $choice->getMasterPictureAttachment() ? $this->attachmentURLGenerator->getThumbnailURL($choice->getMasterPictureAttachment(), 'thumbnail_xs') : null,
];
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf
index 0042506a..9938615b 100644
--- a/translations/messages.en.xlf
+++ b/translations/messages.en.xlf
@@ -10416,5 +10416,17 @@ Element 3
A PCRE-compatible regular expression, which a part name have to match.
+
+
+ entity.select.add_hint
+ to create nested structures, e.g. "Node 1->Node 1.1"]]>
+
+
+
+
+ entity.select.group.new_not_added_to_DB
+ New (not added to DB yet)
+
+