Last active
August 29, 2015 14:26
-
-
Save YuzuruSano/4e5874b44c99c6c9d39d to your computer and use it in GitHub Desktop.
concrete5 5.7でレイアウトを設定したブロックの中身をカラム毎に取得するサンプル。使う場面があまり無さそうだけど、レイアウトを設定したエリアではgetAreaBlocksArrayで各ブロックの情報にアクセスできなかったので。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Concrete\Core\Area\Layout\Layout as AreaLayout; | |
use \Concrete\Block\CoreAreaLayout\Controller as CoreAreaLayout; | |
$a = new Area('area'); | |
$b = $a->getAreaBlocksArray($c); | |
$alid = $b[0]->instance->arLayoutID; | |
$ba = $b[0]->getBlockAreaObject(); | |
$bobj = $b[0]->instance->getBlockObject(); | |
//エリアIDを元にエリアオブジェクトを取得していく | |
$arLayout = AreaLayout::getByID($alid); | |
$arLayout->setBlockObject($bobj); | |
$cal = new CoreAreaLayout(); | |
$cal->arLayout = $arLayout; | |
$cal->arLayout->setAreaObject($ba); | |
//各カラムを取得 | |
$columns = $cal->arLayout->getAreaLayoutColumns(); | |
//各カラムをふつうに出力 | |
foreach($columns as $col) { | |
$col->display(); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use \Concrete\Core\Area\Layout\Layout as AreaLayout; | |
use \Concrete\Block\CoreAreaLayout\Controller as CoreAreaLayout; | |
$a = new Area('area'); | |
$b = $a->getAreaBlocksArray($c); | |
$alid = $b[0]->instance->arLayoutID; | |
$ba = $b[0]->getBlockAreaObject(); | |
$bobj = $b[0]->instance->getBlockObject(); | |
//エリアIDを元にエリアオブジェクトを取得していく | |
$arLayout = AreaLayout::getByID($alid); | |
$arLayout->setBlockObject($bobj); | |
$cal = new CoreAreaLayout(); | |
$cal->arLayout = $arLayout; | |
$cal->arLayout->setAreaObject($ba); | |
//各カラムを取得 | |
$columns = $cal->arLayout->getAreaLayoutColumns(); | |
//各カラムをバラバラにして別の配列に格納して出力 | |
//レイアウト機能だけ管理画面で使用して、フロントは並び替えて加工して出力したいとき?とか? | |
$sorted_blocks = array(); | |
foreach($columns as $col) { | |
$a = $col->getAreaObject();//各カラムをエリアオブジェクトとして取得 | |
$areablocks = $a->getAreaBlocksArray();//カラム内のブロックを配列でもらう | |
$loopcounter = 0; | |
foreach($areablocks as $block){ | |
$sorted_blocks[$loopcounter][] = $block; | |
$loopcounter++; | |
} | |
} | |
foreach($sorted_blocks as $sbs){ | |
foreach($sbs as $b){ | |
$b->display(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment