From 1c2005e6d6db9561e55b243e8bba5821b7b9acae Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Mon, 4 Nov 2024 15:07:08 +0100 Subject: [PATCH 1/9] IBX-9086 Autogenerated identifiers for content types & field definitions --- .../public/js/scripts/admin.contenttype.edit.js | 16 ++++++++++++++++ .../core/slug.value.input.autogenerator.js | 2 +- .../themes/admin/content_type/create.html.twig | 10 ++++++++-- .../themes/admin/content_type/edit.html.twig | 10 ++++++++-- .../content_type/field_definition.html.twig | 8 ++++++-- .../part/field_definition_form.html.twig | 8 ++++++-- 6 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js index 16c01cbb48..50ac595d3d 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js @@ -70,6 +70,20 @@ field.classList.toggle('ibexa-available-field-type--hidden', isFieldHidden); }); }; + const reinitIdentifierAutogenerator = (fieldNode) => { + const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); + sourceInputs.forEach((sourceInput) => { + const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; + const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); + const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ + sourceInput, + targetInput, + whitespaceTextReplacer: '_', + shouldAutogenerateValue: true, + }); + identifierAutogenerator.init(); + }); + } const removeDragPlaceholders = () => { const placeholderNodes = doc.querySelectorAll('.ibexa-field-definitions-placeholder'); @@ -139,6 +153,7 @@ draggableGroups.forEach((group) => { group.reinit(); }); + reinitIdentifierAutogenerator(fieldNode); }; const dispatchInsertFieldDefinitionNode = (fieldNode) => { doc.body.dispatchEvent(new CustomEvent('ibexa-inputs:added')); @@ -651,5 +666,6 @@ false, ); + reinitIdentifierAutogenerator(global.document); toggleAddGroupTriggerBtnState(); })(window, window.document, window.ibexa, window.Routing, window.Translator, window.bootstrap); diff --git a/src/bundle/Resources/public/js/scripts/core/slug.value.input.autogenerator.js b/src/bundle/Resources/public/js/scripts/core/slug.value.input.autogenerator.js index 6ad399febb..5026768d41 100644 --- a/src/bundle/Resources/public/js/scripts/core/slug.value.input.autogenerator.js +++ b/src/bundle/Resources/public/js/scripts/core/slug.value.input.autogenerator.js @@ -4,7 +4,7 @@ this.sourceInput = config.sourceInput; this.targetInput = config.targetInput; this.whitespaceTextReplacer = config.whitespaceTextReplacer || '_'; - this.shouldAutogenerateValue = !this.targetInput.value; + this.shouldAutogenerateValue = config.shouldAutogenerateValue || !this.targetInput.value; } slugify(text) { diff --git a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig index 24ec499a88..1cd871995d 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig @@ -51,8 +51,14 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, form_field_options) }} - {{ form_row(form.identifier, form_field_options) }} + {{ form_row(form.name, { + row_attr: { class: 'ibexa-form-field' }, + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, + }) }} + {{ form_row(form.identifier, { + row_attr: { class: 'ibexa-form-field' }, + attr: { class: 'ibexa-edit-content-type-identifier' }, + }) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig index 6621787597..196044427b 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig @@ -57,8 +57,14 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, form_field_options) }} - {{ form_row(form.identifier, form_field_options) }} + {{ form_row(form.name, { + row_attr: { class: 'ibexa-form-field' }, + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, + }) }} + {{ form_row(form.identifier, { + row_attr: { class: 'ibexa-form-field' }, + attr: { class: 'ibexa-edit-content-type-identifier' }, + }) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig index 8eda7f03bf..af57cf17d9 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig @@ -28,8 +28,12 @@ {% if field_definition.enabled is defined %} {{ form_row(field_definition.enabled) }} {% endif %} - {{ form_row(field_definition.name) }} - {{ form_row(field_definition.identifier) }} + {{ form_row(field_definition.name, { + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + }) }} + {{ form_row(field_definition.identifier, { + attr: { class: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + }) }} {{ form_row(field_definition.description) }} {{ form_row(field_definition.isRequired) }} {{ form_row(field_definition.isSearchable) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig b/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig index 68c6c48860..82e289d5d0 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig @@ -29,8 +29,12 @@ } -%} {%- block body_content -%}
- {{ form_row(form.name) }} - {{ form_row(form.identifier) }} + {{ form_row(form.name, { + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ form.identifier.vars.value } + }) }} + {{ form_row(form.identifier, { + attr: { class: 'ibexa-ct-identifier-' ~ form.identifier.vars.value }, + }) }} {{ form_row(form.description) }} {{ form_row(form.isRequired) }} {{ form_row(form.isSearchable) }} From 271f7ea7abb095d8cb9b57832ffe4548050a8022 Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Mon, 4 Nov 2024 15:12:40 +0100 Subject: [PATCH 2/9] format js file --- .../js/scripts/admin.contenttype.edit.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js index 50ac595d3d..57c9bff968 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js @@ -72,17 +72,17 @@ }; const reinitIdentifierAutogenerator = (fieldNode) => { const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - sourceInputs.forEach((sourceInput) => { - const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; - const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); - const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ - sourceInput, - targetInput, - whitespaceTextReplacer: '_', - shouldAutogenerateValue: true, - }); - identifierAutogenerator.init(); + sourceInputs.forEach((sourceInput) => { + const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; + const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); + const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ + sourceInput, + targetInput, + whitespaceTextReplacer: '_', + shouldAutogenerateValue: true, }); + identifierAutogenerator.init(); + }); } const removeDragPlaceholders = () => { const placeholderNodes = doc.querySelectorAll('.ibexa-field-definitions-placeholder'); From 6c3f4aa8e13940de427e0e4460409f97b8f520be Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Mon, 4 Nov 2024 15:37:09 +0100 Subject: [PATCH 3/9] format js file - semicolon --- .../Resources/public/js/scripts/admin.contenttype.edit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js index 57c9bff968..abcaba9806 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js @@ -83,7 +83,7 @@ }); identifierAutogenerator.init(); }); - } + }; const removeDragPlaceholders = () => { const placeholderNodes = doc.querySelectorAll('.ibexa-field-definitions-placeholder'); From 0afe1edddbfb8510574e248f6ae64cf3792f068a Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Mon, 4 Nov 2024 16:07:30 +0100 Subject: [PATCH 4/9] format twig files --- .../themes/admin/content_type/create.html.twig | 14 +++++++------- .../themes/admin/content_type/edit.html.twig | 16 ++++++++-------- .../content_type/field_definition.html.twig | 8 ++++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig index 1cd871995d..566398ba12 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig @@ -52,13 +52,13 @@ {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} {{ form_row(form.name, { - row_attr: { class: 'ibexa-form-field' }, - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, - }) }} - {{ form_row(form.identifier, { - row_attr: { class: 'ibexa-form-field' }, - attr: { class: 'ibexa-edit-content-type-identifier' }, - }) }} + row_attr: { class: 'ibexa-form-field' }, + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, + }) }} + {{ form_row(form.identifier, { + row_attr: { class: 'ibexa-form-field' }, + attr: { class: 'ibexa-edit-content-type-identifier' }, + }) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig index 196044427b..2122f42836 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig @@ -57,14 +57,14 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, { - row_attr: { class: 'ibexa-form-field' }, - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, - }) }} - {{ form_row(form.identifier, { - row_attr: { class: 'ibexa-form-field' }, - attr: { class: 'ibexa-edit-content-type-identifier' }, - }) }} + {{ form_row(form.name, { + row_attr: { class: 'ibexa-form-field' }, + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, + }) }} + {{ form_row(form.identifier, { + row_attr: { class: 'ibexa-form-field' }, + attr: { class: 'ibexa-edit-content-type-identifier' }, + }) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig index af57cf17d9..e37cc97783 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig @@ -29,11 +29,11 @@ {{ form_row(field_definition.enabled) }} {% endif %} {{ form_row(field_definition.name, { - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } - }) }} + attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + }) }} {{ form_row(field_definition.identifier, { - attr: { class: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } - }) }} + attr: { class: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + }) }} {{ form_row(field_definition.description) }} {{ form_row(field_definition.isRequired) }} {{ form_row(field_definition.isSearchable) }} From fcf16aeb7674bc2c4cdc20d97391c8e2dcc6ede6 Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Mon, 4 Nov 2024 16:09:20 +0100 Subject: [PATCH 5/9] format twig fix --- .../views/themes/admin/content_type/create.html.twig | 2 +- .../themes/admin/content_type/field_definition.html.twig | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig index 566398ba12..1ef52806a5 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig @@ -51,7 +51,7 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, { + {{ form_row(form.name, { row_attr: { class: 'ibexa-form-field' }, attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, }) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig index e37cc97783..a12b7a7f20 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig @@ -28,10 +28,10 @@ {% if field_definition.enabled is defined %} {{ form_row(field_definition.enabled) }} {% endif %} - {{ form_row(field_definition.name, { + {{ form_row(field_definition.name, { attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } }) }} - {{ form_row(field_definition.identifier, { + {{ form_row(field_definition.identifier, { attr: { class: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } }) }} {{ form_row(field_definition.description) }} From a4027b49c87ca3661cc6ec165f14ad63b076f5eb Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Tue, 5 Nov 2024 16:30:09 +0100 Subject: [PATCH 6/9] review fixes --- .../js/scripts/admin.contenttype.edit.js | 26 ++++++-------- .../js/scripts/autogenerate.identifier.js | 34 ++++++++++++++----- .../admin/content_type/create.html.twig | 13 +++---- .../themes/admin/content_type/edit.html.twig | 13 +++---- .../content_type/field_definition.html.twig | 4 +-- .../part/field_definition_form.html.twig | 4 +-- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js index abcaba9806..9c054e9db0 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js @@ -70,20 +70,6 @@ field.classList.toggle('ibexa-available-field-type--hidden', isFieldHidden); }); }; - const reinitIdentifierAutogenerator = (fieldNode) => { - const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - sourceInputs.forEach((sourceInput) => { - const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; - const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); - const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ - sourceInput, - targetInput, - whitespaceTextReplacer: '_', - shouldAutogenerateValue: true, - }); - identifierAutogenerator.init(); - }); - }; const removeDragPlaceholders = () => { const placeholderNodes = doc.querySelectorAll('.ibexa-field-definitions-placeholder'); @@ -153,7 +139,6 @@ draggableGroups.forEach((group) => { group.reinit(); }); - reinitIdentifierAutogenerator(fieldNode); }; const dispatchInsertFieldDefinitionNode = (fieldNode) => { doc.body.dispatchEvent(new CustomEvent('ibexa-inputs:added')); @@ -162,6 +147,11 @@ detail: { nodes: [fieldNode] }, }), ); + doc.body.dispatchEvent( + new CustomEvent('ibexa-recall-autogenerate-identifier', { + detail: { fieldNode, shouldAutogenerateValue: true }, + }), + ); }; const insertFieldDefinitionNode = (fieldNode, { targetContainer, draggedItemPosition }) => { const fieldDefinitionNode = createFieldDefinitionNode(fieldNode, { targetContainer, draggedItemPosition }); @@ -666,6 +656,10 @@ false, ); - reinitIdentifierAutogenerator(global.document); + doc.body.dispatchEvent( + new CustomEvent('ibexa-recall-autogenerate-identifier', { + detail: { fieldNode: global.document, shouldAutogenerateValue: true }, + }), + ); toggleAddGroupTriggerBtnState(); })(window, window.document, window.ibexa, window.Routing, window.Translator, window.bootstrap); diff --git a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js index 40339cf92b..f672541c32 100644 --- a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js +++ b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js @@ -1,14 +1,32 @@ (function (doc, ibexa) { const sourceInputs = doc.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - sourceInputs.forEach((sourceInput) => { - const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; - const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); - const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ - sourceInput, - targetInput, + const generateIdentifier = (elements, shouldAutogenerateValue = false) => { + elements.forEach((sourceInput) => { + const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; + const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); + const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ + sourceInput, + targetInput, + shouldAutogenerateValue: shouldAutogenerateValue, + }); + identifierAutogenerator.init(); }); + }; - identifierAutogenerator.init(); - }); + const attachListeners = () => { + doc.body.addEventListener( + 'ibexa-recall-autogenerate-identifier', + (event) => { + const { fieldNode, shouldAutogenerateValue } = event.detail; + const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); + + generateIdentifier(sourceInputs, shouldAutogenerateValue); + }, + false, + ); + }; + + generateIdentifier(sourceInputs); + attachListeners(); })(document, window.ibexa); diff --git a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig index 1ef52806a5..dd98a3e6eb 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/create.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/create.html.twig @@ -51,14 +51,11 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, { - row_attr: { class: 'ibexa-form-field' }, - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, - }) }} - {{ form_row(form.identifier, { - row_attr: { class: 'ibexa-form-field' }, - attr: { class: 'ibexa-edit-content-type-identifier' }, - }) }} + {{ form_row(form.name, form_field_options|merge({ + attr: { 'data-autogenerate-identifier-target-selector': '#ibexa-edit-content-type-identifier' } } + )) }} + {{ form_row(form.identifier, form_field_options|merge({ + id: 'ibexa-edit-content-type-identifier' } ) ) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig index 2122f42836..ee1c92af27 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/edit.html.twig @@ -57,14 +57,11 @@ {% block left_column %} {% set form_field_options = { row_attr: { class: 'ibexa-form-field' } } %} - {{ form_row(form.name, { - row_attr: { class: 'ibexa-form-field' }, - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-edit-content-type-identifier' }, - }) }} - {{ form_row(form.identifier, { - row_attr: { class: 'ibexa-form-field' }, - attr: { class: 'ibexa-edit-content-type-identifier' }, - }) }} + {{ form_row(form.name, form_field_options|merge({ + attr: { 'data-autogenerate-identifier-target-selector': '#ibexa-edit-content-type-identifier' } } + )) }} + {{ form_row(form.identifier, form_field_options|merge({ + id: 'ibexa-edit-content-type-identifier' } ) ) }} {{ form_row(form.description, form_field_options) }} {{ form_row(form.nameSchema, form_field_options) }} {{ form_row(form.urlAliasSchema, form_field_options) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig index a12b7a7f20..eebac98857 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/field_definition.html.twig @@ -29,10 +29,10 @@ {{ form_row(field_definition.enabled) }} {% endif %} {{ form_row(field_definition.name, { - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + attr: { 'data-autogenerate-identifier-target-selector': '#ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } }) }} {{ form_row(field_definition.identifier, { - attr: { class: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier } + id: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier }) }} {{ form_row(field_definition.description) }} {{ form_row(field_definition.isRequired) }} diff --git a/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig b/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig index 82e289d5d0..ac31c17a8a 100644 --- a/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig +++ b/src/bundle/Resources/views/themes/admin/content_type/part/field_definition_form.html.twig @@ -30,10 +30,10 @@ {%- block body_content -%}
{{ form_row(form.name, { - attr: { 'data-autogenerate-identifier-target-selector': '.ibexa-ct-identifier-' ~ form.identifier.vars.value } + attr: { 'data-autogenerate-identifier-target-selector': '#ibexa-ct-identifier-' ~ form.identifier.vars.value } }) }} {{ form_row(form.identifier, { - attr: { class: 'ibexa-ct-identifier-' ~ form.identifier.vars.value }, + id: 'ibexa-ct-identifier-' ~ form.identifier.vars.value }) }} {{ form_row(form.description) }} {{ form_row(form.isRequired) }} From 8417f4745724581397218cf62facb27abec54d7b Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Wed, 6 Nov 2024 09:09:10 +0100 Subject: [PATCH 7/9] review fixes pt 2 --- .../public/js/scripts/admin.contenttype.edit.js | 7 +------ .../public/js/scripts/autogenerate.identifier.js | 11 ++++++----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js index 9c054e9db0..a88491860a 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.edit.js @@ -148,7 +148,7 @@ }), ); doc.body.dispatchEvent( - new CustomEvent('ibexa-recall-autogenerate-identifier', { + new CustomEvent('ibexa-autogenerate-identifier:init', { detail: { fieldNode, shouldAutogenerateValue: true }, }), ); @@ -656,10 +656,5 @@ false, ); - doc.body.dispatchEvent( - new CustomEvent('ibexa-recall-autogenerate-identifier', { - detail: { fieldNode: global.document, shouldAutogenerateValue: true }, - }), - ); toggleAddGroupTriggerBtnState(); })(window, window.document, window.ibexa, window.Routing, window.Translator, window.bootstrap); diff --git a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js index f672541c32..9a9a24a067 100644 --- a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js +++ b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js @@ -1,32 +1,33 @@ (function (doc, ibexa) { const sourceInputs = doc.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - const generateIdentifier = (elements, shouldAutogenerateValue = false) => { + const initAutogenerator = (elements, shouldAutogenerateValue = false) => { elements.forEach((sourceInput) => { const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ sourceInput, targetInput, - shouldAutogenerateValue: shouldAutogenerateValue, + shouldAutogenerateValue, }); + identifierAutogenerator.init(); }); }; const attachListeners = () => { doc.body.addEventListener( - 'ibexa-recall-autogenerate-identifier', + 'ibexa-autogenerate-identifier:init', (event) => { const { fieldNode, shouldAutogenerateValue } = event.detail; const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - generateIdentifier(sourceInputs, shouldAutogenerateValue); + initAutogenerator(sourceInputs, shouldAutogenerateValue); }, false, ); }; - generateIdentifier(sourceInputs); + initAutogenerator(sourceInputs); attachListeners(); })(document, window.ibexa); From 27ff2b2ff6fd821cd88cfa4c8b155964c1c3b926 Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Wed, 6 Nov 2024 09:58:07 +0100 Subject: [PATCH 8/9] review fixes pt 3 --- .../public/js/scripts/autogenerate.identifier.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js index 9a9a24a067..078b9788fa 100644 --- a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js +++ b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js @@ -1,14 +1,14 @@ (function (doc, ibexa) { const sourceInputs = doc.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - const initAutogenerator = (elements, shouldAutogenerateValue = false) => { + const initAutogenerator = (elements, shouldAutogenerateValue) => { elements.forEach((sourceInput) => { const { autogenerateIdentifierTargetSelector } = sourceInput.dataset; const targetInput = doc.querySelector(autogenerateIdentifierTargetSelector); const identifierAutogenerator = new ibexa.core.SlugValueInputAutogenerator({ sourceInput, targetInput, - shouldAutogenerateValue, + shouldAutogenerateValue: shouldAutogenerateValue || !targetInput.value, }); identifierAutogenerator.init(); @@ -20,9 +20,9 @@ 'ibexa-autogenerate-identifier:init', (event) => { const { fieldNode, shouldAutogenerateValue } = event.detail; - const sourceInputs = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); + const sourceFields = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]'); - initAutogenerator(sourceInputs, shouldAutogenerateValue); + initAutogenerator(sourceFields, shouldAutogenerateValue); }, false, ); From f30925f57f5e92f0482fcf114ca7315045114d83 Mon Sep 17 00:00:00 2001 From: Aleksandra Bozek Date: Fri, 8 Nov 2024 11:02:31 +0100 Subject: [PATCH 9/9] remove empty line --- .../Resources/public/js/scripts/autogenerate.identifier.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js index 078b9788fa..d87895c89b 100644 --- a/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js +++ b/src/bundle/Resources/public/js/scripts/autogenerate.identifier.js @@ -14,7 +14,6 @@ identifierAutogenerator.init(); }); }; - const attachListeners = () => { doc.body.addEventListener( 'ibexa-autogenerate-identifier:init',