Commonly, you see "fullTitle" fields, like this, for supporting readable names on nested documents:
import type { FieldHook } from "payload/types";
export const generateFullTitle = (breadcrumbs: unknown): string | undefined => {
if (Array.isArray(breadcrumbs)) {
console.log(breadcrumbs);
return breadcrumbs.reduce((title, breadcrumb, i) => {
if (i === 0) return `${breadcrumb.label}`;
return `${title} > ${breadcrumb.label}`;
}, "");
}
return undefined;
};
const populateFullTitle: FieldHook = async ({ data, originalDoc }) =>
generateFullTitle(data?.breadcrumbs || originalDoc?.breadcrumbs);
export default populateFullTitle;
however, it will always be overriden by whichever language last edited it, rather than maintaining a full title for each user language.
I'd really appreciate an example of how to solve this sort of thing
Hello, I can show you mine, if you want, it works well with multi locales
I named it _breadcrumb, not fullTitle but that's the same
I use nested doc official plugin to get the
breadcrumbs
array
thank you 🙂
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.