Editorial Content Types
We are referring to the content types defined in the traditional way that you want to edit with the page editor.
Differences with CMS Types:
- editorials have their own workspace and can have custom filters
- editorials can have more advanced metadata fields, multiple schemas and other business logic
CMS Types are actually simpler.
Using Editorial Content Types with the Page Builder
- on the primary metadata schema you need to add a slug like this:
{
"name": "slug",
"label_key": "Slug",
"type": "string",
"short_description": "the slug will be generated automatically upon save if empty",
"table": "assets",
"length": 2048,
"editor_config": {
"editor_type": "input",
"editor_subtype": "text"
}
}
- you need to add a hook of type
metadata-services::before-save-adapters
to ensure that the slug is always valued and is unique in the property. Example:
Plugins::registerHook('metadata-services::before-save-adapters', 'set-slug', function($assetId, $dto, $mds, array $options) {
$asset = AssetServices::getAsset($assetId);
if ($asset->assetSubtype == 'Article') {
CmsUtils::manageSlugUpdate($dto, $asset);
- you need to update the asset type hooks of the editorial type as follows:
// if I click on an editorial article it must open the page editor
$hooks['workspace-navigation'] = static function($asset) {
$pushParam = Breadcrumbs::getPushParam();
$pageEditorUrl = getModuleUrl("Cms/pages/page-editor/page-editor.php?assetId=$asset->assetId&$pushParam");
return "onclick='window.location = \"$pageEditorUrl\"'";
} ;
// Upon creation, the asset must be bound to the current property
$hooks['on_created'] = static function($asset) {
$currentPropertyId = CmsPropertyServices::getCurrentUserPropertyId();
if ($currentPropertyId !== null) {
CmsPropertyServices::bindContentToProperty($asset->assetId, $currentPropertyId);
}
};
// when the asset is created it must send me to the page editor
$hooks['on_created_redirect_url'] = getModuleUrl("Cms/pages/page-editor/page-editor.php?assetId=#assetId#");