rewrite Form.getLabel

This commit is contained in:
Apollinaire 2019-01-29 18:41:50 +01:00
parent fe13c451cf
commit 78af913820

View file

@ -516,26 +516,15 @@ class SmartForm extends Component {
*/
getLabel = (fieldName, fieldLocale) => {
const collectionName = this.props.collectionName.toLowerCase();
const defaultMessage = '|*|*|';
let id = `${collectionName}.${fieldName}`;
let intlLabel;
intlLabel = this.context.intl.formatMessage({ id, defaultMessage });
if (intlLabel === defaultMessage) {
id = `global.${fieldName}`;
intlLabel = this.context.intl.formatMessage({ id, defaultMessage });
if (intlLabel === defaultMessage) {
id = fieldName;
intlLabel = this.context.intl.formatMessage({ id });
}
}
const schemaLabel =
this.state.flatSchema[fieldName] &&
this.state.flatSchema[fieldName].label;
const label = intlLabel || schemaLabel || fieldName;
const label = this.context.intl.formatLabel({
fieldName: fieldName,
collectionName: collectionName,
schema: this.state.flatSchema,
});
if (fieldLocale) {
const intlFieldLocale = this.context.intl.formatMessage({
id: `locales.${fieldLocale}`,
defaultMessage: fieldLocale
defaultMessage: fieldLocale,
});
return `${label} (${intlFieldLocale})`;
} else {