mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 01:09:49 +00:00
Merge branch 'features/custom-fields' of github.com:strapi/strapi into custom-fields/add-custom-field-attribute
This commit is contained in:
commit
c894c071f3
@ -1,34 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const { formatAttribute } = require('../attributes');
|
|
||||||
|
|
||||||
describe('format attributes', () => {
|
|
||||||
it('replaces type customField with the underlying data type', () => {
|
|
||||||
const mockAttribute = {
|
|
||||||
type: 'customField',
|
|
||||||
customField: 'plugin::mycustomfields.color',
|
|
||||||
};
|
|
||||||
|
|
||||||
global.strapi = {
|
|
||||||
container: {
|
|
||||||
// mock container.get('custom-fields')
|
|
||||||
get: jest.fn(() => ({
|
|
||||||
// mock container.get('custom-fields').get(uid)
|
|
||||||
get: jest.fn(() => ({
|
|
||||||
name: 'color',
|
|
||||||
plugin: 'mycustomfields',
|
|
||||||
type: 'text',
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const formattedAttribute = formatAttribute('key', mockAttribute);
|
|
||||||
|
|
||||||
const expected = {
|
|
||||||
type: 'text',
|
|
||||||
customField: 'plugin::mycustomfields.color',
|
|
||||||
};
|
|
||||||
expect(formattedAttribute).toEqual(expected);
|
|
||||||
});
|
|
||||||
});
|
|
@ -67,15 +67,6 @@ const formatAttribute = (key, attribute) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attribute.type === 'customField') {
|
|
||||||
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
|
||||||
|
|
||||||
return {
|
|
||||||
...attribute,
|
|
||||||
type: customField.type,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return attribute;
|
return attribute;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ const bootstrap = require('./core/bootstrap');
|
|||||||
const loaders = require('./core/loaders');
|
const loaders = require('./core/loaders');
|
||||||
const { destroyOnSignal } = require('./utils/signals');
|
const { destroyOnSignal } = require('./utils/signals');
|
||||||
const sanitizersRegistry = require('./core/registries/sanitizers');
|
const sanitizersRegistry = require('./core/registries/sanitizers');
|
||||||
|
const convertCustomFieldType = require('./utils/convert-custom-field-type');
|
||||||
|
|
||||||
// TODO: move somewhere else
|
// TODO: move somewhere else
|
||||||
const draftAndPublishSync = require('./migrations/draft-publish');
|
const draftAndPublishSync = require('./migrations/draft-publish');
|
||||||
@ -428,6 +429,8 @@ class Strapi {
|
|||||||
|
|
||||||
async load() {
|
async load() {
|
||||||
await this.register();
|
await this.register();
|
||||||
|
// Swap type customField for underlying data type
|
||||||
|
convertCustomFieldType(this);
|
||||||
await this.bootstrap();
|
await this.bootstrap();
|
||||||
|
|
||||||
this.isLoaded = true;
|
this.isLoaded = true;
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const convertCustomFieldType = require('../convert-custom-field-type');
|
||||||
|
|
||||||
|
describe('format attributes', () => {
|
||||||
|
it('replaces type customField with the underlying data type', () => {
|
||||||
|
global.strapi = {
|
||||||
|
container: {
|
||||||
|
// mock container.get('custom-fields')
|
||||||
|
get: jest.fn(() => ({
|
||||||
|
// mock container.get('custom-fields').get(uid)
|
||||||
|
get: jest.fn(() => ({
|
||||||
|
name: 'color',
|
||||||
|
plugin: 'mycustomfields',
|
||||||
|
type: 'text',
|
||||||
|
})),
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
contentTypes: {
|
||||||
|
test: {
|
||||||
|
attributes: {
|
||||||
|
color: {
|
||||||
|
type: 'customField',
|
||||||
|
customField: 'plugin::mycustomfields.color',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
convertCustomFieldType(global.strapi);
|
||||||
|
|
||||||
|
const expected = {
|
||||||
|
...global.strapi,
|
||||||
|
contentTypes: {
|
||||||
|
test: {
|
||||||
|
attributes: {
|
||||||
|
color: {
|
||||||
|
type: 'text',
|
||||||
|
customField: 'plugin::mycustomfields.color',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(global.strapi).toEqual(expected);
|
||||||
|
});
|
||||||
|
});
|
15
packages/core/strapi/lib/utils/convert-custom-field-type.js
Normal file
15
packages/core/strapi/lib/utils/convert-custom-field-type.js
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const convertCustomFieldType = strapi => {
|
||||||
|
const allSchemasAttributes = Object.values(strapi.contentTypes).map(schema => schema.attributes);
|
||||||
|
for (const schemaAttrbutes of allSchemasAttributes) {
|
||||||
|
for (const attribute of Object.values(schemaAttrbutes)) {
|
||||||
|
if (attribute.type === 'customField') {
|
||||||
|
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
||||||
|
attribute.type = customField.type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = convertCustomFieldType;
|
@ -19,11 +19,6 @@ const cleanSchemaAttributes = (attributes, { typeMap = new Map(), isRequest = fa
|
|||||||
delete attributesCopy[prop].default;
|
delete attributesCopy[prop].default;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attribute.type === 'customField') {
|
|
||||||
const customField = strapi.container.get('custom-fields').get(attribute.customField);
|
|
||||||
attribute.type = customField.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (attribute.type) {
|
switch (attribute.type) {
|
||||||
case 'password': {
|
case 'password': {
|
||||||
if (!isRequest) {
|
if (!isRequest) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user