Hi, I need to extend the CMS Page model with custom fields. I’ve been doing that using the backend.form.extendFields event in OC1. But in this case I’d like to have some custom properties that depend on the site (and not necesarily on the locale). I’d like to have some indication just to get started on the right direction.
I’ll really appretiate the help.
Thanks,
Hi, thanks. In fact I had read that and tried it. I have succesfully extended the cms pages with custom fields. But my issue starts when I need per locale or per site fields. I honestly couldn’t achieve that. I think adding a point in that article that tackles those needs would be much appretiated.
The translate plugin solves this by adding a new tab for each locale. Here is an example:
Event::listen('cms.template.getTemplateToolbarSettingsButtons', function($extension, $dataHolder) {
if ($dataHolder->templateType !== 'page') {
return;
}
if (!LocaleModel::isAvailable()) {
return;
}
$locales = LocaleModel::listAvailable();
$defaultLocale = LocaleModel::getDefault()->code ?? null;
$properties = [];
foreach ($locales as $locale => $label) {
if ($locale == $defaultLocale) {
continue;
}
$properties[] = [
'property' => 'localeUrl.'.$locale,
'title' => 'cms::lang.editor.url',
'tab' => $label,
'type' => 'string',
];
$properties[] = [
'property' => 'localeTitle.'.$locale,
'title' => 'cms::lang.editor.title',
'tab' => $label,
'type' => 'string',
];
}
$dataHolder->buttons[] = [
'button' => 'Translate',
'icon' => 'octo-icon-globe',
'popupTitle' => 'Translate Page Properties',
'properties' => $properties
];
});