我正在尝试加入“发布页面类型”事件,以便可以使用页面属性来选择要使用的语言,从而同时在多个语言站点中发布同一页面。下面的代码运行正常,没有错误,但是我没有使用目标语言创建重复的页面,而是获得了原始语言的新页面草稿。我在这里想念什么?
代码
<?php
Events::addListener('on_page_type_publish',
function($event) {
$page = $event->getPageObject();
if ($page->getPageTypeHandle() == 'blog_entry') {
$multilingualController = Core::make('\Concrete\Controller\Backend\Page\Multilingual');
$multilingualController->setPageObject($page);
$pageCollection = $page->getCollectionID();
$pageSection = \Concrete\Core\Multilingual\Page\Section\Section::getBySectionOfSite($page);
$pageLocaleText = $pageSection->getLanguageText();
$targetLocale = \Concrete\Core\Multilingual\Page\Section\Section::getByLocale('nb_NO'); //Will be set from page attribute
$targetLocaleCollection = $targetLocale->getCollectionID();
$createNewData = array(
'section' => $targetLocaleCollection,
'cID' => $pageCollection
);
$action = $multilingualController->action('create_new', $createNewData);
$theResult = $multilingualController->runAction($action, $createNewData);
}
});