Skip to content

Commit

Permalink
Add AffiliationWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarde committed May 15, 2024
1 parent 2530ff6 commit afe7e23
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
66 changes: 66 additions & 0 deletions frontend/src/components/Widgets/Affiliation/AffiliationWidget.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { defineMessages } from 'react-intl';

import ObjectListWidget from '@plone/volto/components/manage/Widgets/ObjectListWidget';

const messages = defineMessages({
item: {
id: 'Item',
defaultMessage: 'Item',
},
addItem: {
id: 'Add item',
defaultMessage: 'Add item',
},
labelFunction: {
id: 'Function',
defaultMessage: 'Function',
},
labelSelectInstitution: {
id: 'Select institution',
defaultMessage: 'Select institution',
},
});

const ItemSchema = (intl) => {
return {
title: intl.formatMessage(messages.item),
addMessage: intl.formatMessage(messages.addItem),
properties: {
href: {
title: intl.formatMessage(messages.labelSelectInstitution),
widget: 'object_browser',
mode: 'link',
widgetOptions: {
pattern_options: { selectableTypes: ['Subsite'] },
},
selectedItemAttrs: ['title'],
allowExternals: false,
},
function: {
title: intl.formatMessage(messages.labelFunction),
},
},
fieldsets: [
{
id: 'default',
title: intl.formatMessage(messages.item),
fields: ['href', 'function'],
},
],
required: ['text'],
};
};

const AffiliationWidget = (props) => {
const itemSchema = ItemSchema(props.intl);
return (
<ObjectListWidget
schema={itemSchema}
{...props}
value={props.value?.items || props.default?.items || []}
onChange={(id, value) => props.onChange(id, { items: value })}
/>
);
};

export default AffiliationWidget;
4 changes: 4 additions & 0 deletions frontend/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

// [Internal] All the imports of modules required for the configuration *must* happen
// here BEFORE the following line
import AffiliationWidget from '@package/components/Widgets/Affiliation/AffiliationWidget';

import '@plone/volto/config';

export default function applyConfig(config) {
config.widgets.widget.affiliation_widget = AffiliationWidget;

return config;
}

0 comments on commit afe7e23

Please sign in to comment.