Skip to content
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
1 change: 1 addition & 0 deletions packages/volto/news/+schema-widget-factory.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix SchemaWidget to send the field factory as a string instead of an object to the backend, and pass `filterFactory` in the types control panel to only allow valid content type field types. @Shyam-Raghuwanshi
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,33 @@ class ContentTypeSchema extends Component {

form = React.createRef();

/**
* List of field factory tokens that are valid for content type schemas.
* These correspond to IFieldFactory utilities registered on the backend.
* Form-only field types (e.g., static_text, hidden, radio_group) are
* excluded since they don't have corresponding Plone field factories.
*/
contentTypeFieldFactories = [
'label_textline_field',
'label_text_field',
'label_integer_field',
'label_float_field',
'label_boolean_field',
'label_password_field',
'label_datetime_field',
'label_date_field',
'label_choice_field',
'label_multi_choice_field',
'label_email',
'Rich Text',
'URL',
'File Upload',
'Image',
'Relation List',
'Relation Choice',
'JSONField',
];

makeSchemaList = (schema) => {
const result = {
title: 'Schema',
Expand All @@ -217,6 +244,13 @@ class ContentTypeSchema extends Component {
type: 'schema',
id: 'schema',
widget: 'schema',
widgetOptions: {
frontendOptions: {
widgetProps: {
filterFactory: this.contentTypeFieldFactories,
},
},
},
},
},
required: [],
Expand Down
17 changes: 12 additions & 5 deletions packages/volto/src/components/manage/Widgets/SchemaWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,10 @@ class SchemaWidget extends Component {
* @returns {undefined}
*/
onAddField(values) {
const factory =
typeof values.factory === 'object' && values.factory !== null
? values.factory.value
: values.factory;
const fieldId = slugify(
values.id || values.title,
keys(this.props.value.properties),
Expand All @@ -1023,19 +1027,18 @@ class SchemaWidget extends Component {
: [...currentFieldsetFields, fieldId];

const utility = config.getUtility({
name: values.factory,
name: factory,
type: 'fieldFactoryInitialData',
});

const multiple =
values.factory === 'Multiple Choice' ||
values.factory === 'label_multi_choice_field';
factory === 'Multiple Choice' || factory === 'label_multi_choice_field';

const initialData = utility.method
? omit(utility.method(this.props.intl), ['id'])
: {
type: 'string',
factory: values.factory,
factory: factory,
};

this.onChange({
Expand Down Expand Up @@ -1795,8 +1798,12 @@ class SchemaWidget extends Component {
onCancel={this.onCancel}
className={`field-${slugify(isString(this.state.addField) && this.state.addField !== '' ? this.state.addField : 'label_text_field')}`}
onChangeFormData={(data) => {
const factoryValue =
typeof data.factory === 'object' && data.factory !== null
? data.factory.value
: data.factory;
this.setState({
addField: data.factory,
addField: factoryValue,
});
}}
title={this.props.intl.formatMessage(messages.addField)}
Expand Down