/**
  * Set data for this page's blocks.
  *
  * @param array $blocksData An array of key-value arrays for each block.
  * @param boolean $deleteExtras Whether to delete any extra preexisting
  *  blocks.
  */
 public function setPageBlocks($blocksData, $deleteExtras = true)
 {
     $existingBlocks = $this->getPageBlocks();
     foreach ($blocksData as $i => $blockData) {
         if (!empty($existingBlocks)) {
             $block = array_pop($existingBlocks);
         } else {
             $block = new ExhibitPageBlock();
             $block->page_id = $this->id;
         }
         $block->order = $i;
         $block->setData($blockData);
         $block->save();
     }
     // Any leftover blocks beyond the new data get erased.
     if ($deleteExtras) {
         foreach ($existingBlocks as $extraBlock) {
             $extraBlock->delete();
         }
     }
 }
 /**
  * Create an exhibit page block.
  *
  * @param ExhibitPage $page The parent page.
  * @param string $text The entry content.
  * @param integer $order The entry order.
  * @return ExhibitPageBlock
  */
 protected function _exhibitBlock($page = null, $text = 'Test text.')
 {
     // Create a parent page if none is passed.
     if (is_null($page)) {
         $page = $this->_exhibitPage();
     }
     $block = new ExhibitPageBlock();
     $block->page_id = $page->id;
     $block->text = $text;
     $block->layout = 'text';
     $block->save();
     return $block;
 }