コード例 #1
0
 public function testProperties()
 {
     /** test getCode */
     $this->assertEquals($this->blockCode, $this->blockConfig->getCode());
     /** test setCode */
     $this->blockConfig->setCode($this->testCode);
     $this->assertEquals($this->testCode, $this->blockConfig->getCode());
     /** test getTitle */
     $this->assertNull($this->blockConfig->getTitle());
     /** test setTitle */
     $this->blockConfig->setTitle($this->testTitle);
     $this->assertEquals($this->testTitle, $this->blockConfig->getTitle());
     /** test getPriority */
     $this->assertNull($this->blockConfig->getPriority());
     /** test setPriority */
     $this->blockConfig->setPriority(10);
     $this->assertEquals(10, $this->blockConfig->getPriority());
     /** test getClass */
     $this->assertNull($this->blockConfig->getClass());
     /** test setClass */
     $this->blockConfig->setClass($this->testClass);
     $this->assertEquals($this->testClass, $this->blockConfig->getClass());
     /** test getSubBlock */
     $this->assertEquals(array(), $this->blockConfig->getSubBlocks());
     /** test setSubBlocks */
     $this->blockConfig->setSubBlocks($this->testSubBlocks);
     $this->assertEquals($this->testSubBlocks, $this->blockConfig->getSubBlocks());
     /** test setDescription */
     $this->blockConfig->setDescription($this->testDescription);
     $this->assertEquals($this->testDescription, $this->blockConfig->getDescription());
     /** test hasSubBlock */
     $this->assertFalse($this->blockConfig->hasSubBlock('testSubBlock'));
     /** test setSubBlock */
     $subblocks = array();
     foreach ($this->testSubBlocksConfig as $code => $data) {
         $blockDescription = !empty($data['description']) ? $data['description'] : null;
         $subblocks[] = array('code' => $code, 'title' => $data['title'], 'data' => array('some_data'), 'description' => $blockDescription, 'useSpan' => true);
         $subBlock = new SubBlockConfig($code);
         /** test SubBlockConfig set/get Title/Priority/Code */
         $subBlock->setTitle($data['title']);
         $this->assertEquals($data['title'], $subBlock->getTitle());
         $subBlock->setPriority($data['priority']);
         $this->assertEquals($data['priority'], $subBlock->getPriority());
         $subBlock->setCode($code);
         $this->assertEquals($code, $subBlock->getCode());
         $subBlock->setData(array('some_data'));
         $this->assertEquals(array('some_data'), $subBlock->getData());
         $subBlock->setUseSpan(true);
         $this->assertTrue($subBlock->getUseSpan());
         $subBlock->setDescription($blockDescription);
         $this->assertEquals($blockDescription, $subBlock->getDescription());
         /** test SubBlockConfig addSubBlock */
         $this->blockConfig->addSubBlock($subBlock);
         $this->assertEquals($subBlock, $this->blockConfig->getSubBlock($code));
         $this->testSubBlocks[] = $subBlock;
     }
     $this->blockConfig->setSubBlocks($this->testSubBlocks);
     $this->assertEquals($this->testSubBlocks, $this->blockConfig->getSubBlocks());
     $this->assertEquals(array('title' => $this->testTitle, 'class' => $this->testClass, 'subblocks' => $subblocks, 'description' => $this->testDescription), $this->blockConfig->toArray());
 }
コード例 #2
0
 /**
  * @param        $code
  * @param  array $blockConfig
  * @return BlockConfig
  */
 protected function createBlock($code, $blockConfig = [])
 {
     if ($this->formConfig->hasBlock($code)) {
         $block = $this->formConfig->getBlock($code);
     } else {
         $block = new BlockConfig($code);
     }
     $block->setClass($this->accessor->getValue($blockConfig, '[class]'));
     $block->setPriority($this->accessor->getValue($blockConfig, '[priority]'));
     $title = $this->accessor->getValue($blockConfig, '[title]') ? $this->accessor->getValue($blockConfig, '[title]') : ucfirst($code);
     $block->setTitle($title);
     $block->setDescription($this->accessor->getValue($blockConfig, '[description]'));
     foreach ((array) $this->accessor->getValue($blockConfig, '[subblocks]') as $subCode => $subBlockConfig) {
         $block->addSubBlock($this->createSubBlock($subCode, (array) $subBlockConfig));
     }
     $this->formConfig->addBlock($block);
     return $block;
 }
コード例 #3
0
 /**
  * @param string $code
  * @param array  $config
  *
  * @return BlockConfig
  */
 protected function addBlock($code, $config = [])
 {
     if ($this->formConfig->hasBlock($code)) {
         $block = $this->formConfig->getBlock($code);
     } else {
         $block = new BlockConfig($code);
     }
     if (!empty($config['title'])) {
         $block->setTitle($config['title']);
     } else {
         $title = $block->getTitle();
         if (empty($title)) {
             $block->setTitle(ucfirst($code));
         }
     }
     if ($this->hasValue($config, 'description')) {
         $block->setDescription($config['description']);
     }
     if ($this->hasValue($config, 'class')) {
         $block->setClass($config['class']);
     }
     if ($this->hasValue($config, 'priority')) {
         $block->setPriority($config['priority']);
     }
     if (!empty($config['subblocks'])) {
         foreach ($config['subblocks'] as $subBlockCode => $subBlockConfig) {
             $this->addSubBlock($block, $subBlockCode, (array) $subBlockConfig);
         }
     }
     $this->formConfig->addBlock($block);
     return $block;
 }