Skip to content

Instantly share code, notes, and snippets.

@YuzuruSano
Last active November 24, 2016 15:27
Show Gist options
  • Save YuzuruSano/a775700f6de204c8bd2a40bd9eb3e46f to your computer and use it in GitHub Desktop.
Save YuzuruSano/a775700f6de204c8bd2a40bd9eb3e46f to your computer and use it in GitHub Desktop.
コンポーザーを通して新規ページを追加して、初期出力の記事ブロックに記事を挿入する。自動実行ジョブにどうぞ
<?php
//ページタイプの「出力」で'Main'エリアにコンポーザーで扱うcontentブロックを入れてる場合
$pageType = \PageType::getByHandle('ページタイプハンドル');
$template = $pageType->getPageTypeDefaultPageTemplateObject();
$d = $pageType->createDraft($template);
$d->setPageDraftTargetParentPageID(親ページID);
$pageType->savePageTypeComposerForm($d);
$pageType->publish($d);
//$dには追加したページオブジェクトが入ってくる
$d->update(
array(
'cName' => 'sample_cName',//タイトル
'cDescription' => 'cDesc',//説明
'cHandle' => 'sample_cHandle'//スラッグ
)
);
$blocks = $d->getBlocks('Main');
if(is_array($blocks)){
foreach($blocks as $block){
if($block->btHandle == 'content'){
$block->update(array(
'content' => 'テスト記事を"Main"エリアの記事ブロックに挿入_'
));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment