Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9086 Autogenerated identifiers for content types & field definitions #1389

Open
wants to merge 9 commits into
base: 4.6
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@
detail: { nodes: [fieldNode] },
}),
);
doc.body.dispatchEvent(
new CustomEvent('ibexa-autogenerate-identifier:init', {
detail: { fieldNode, shouldAutogenerateValue: true },
}),
);
};
const insertFieldDefinitionNode = (fieldNode, { targetContainer, draggedItemPosition }) => {
const fieldDefinitionNode = createFieldDefinitionNode(fieldNode, { targetContainer, draggedItemPosition });
Expand Down
34 changes: 26 additions & 8 deletions src/bundle/Resources/public/js/scripts/autogenerate.identifier.js
Original file line number Diff line number Diff line change
@@ -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 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 || !targetInput.value,
});

identifierAutogenerator.init();
bozatko marked this conversation as resolved.
Show resolved Hide resolved
});
};
const attachListeners = () => {
doc.body.addEventListener(
'ibexa-autogenerate-identifier:init',
(event) => {
const { fieldNode, shouldAutogenerateValue } = event.detail;
const sourceFields = fieldNode.querySelectorAll('[data-autogenerate-identifier-target-selector]');

initAutogenerator(sourceFields, shouldAutogenerateValue);
},
false,
);
};

identifierAutogenerator.init();
});
initAutogenerator(sourceInputs);
attachListeners();
})(document, window.ibexa);
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,11 @@
{% 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, 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) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@
{% 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, 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) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
id: 'ibexa-ct-identifier-' ~ field_definition.vars.value.identifier
}) }}
{{ form_row(field_definition.description) }}
{{ form_row(field_definition.isRequired) }}
{{ form_row(field_definition.isSearchable) }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
} -%}
{%- block body_content -%}
<div class="ibexa-content-type-edit__field-definition-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, {
id: 'ibexa-ct-identifier-' ~ form.identifier.vars.value
}) }}
{{ form_row(form.description) }}
{{ form_row(form.isRequired) }}
{{ form_row(form.isSearchable) }}
Expand Down
Loading