Esempio n. 1
0
 public function testAddBlock()
 {
     /** test getBlocks without any adjusted block(s) */
     $this->assertEquals(array(), $this->formConfig->getBlocks());
     /** test hasBlock without any adjusted block(s) */
     $this->assertFalse($this->formConfig->hasBlock('testBlock'));
     /** @var BlockConfig $blockConfig */
     $blockConfig = new BlockConfig('testBlock');
     $blockConfig->setTitle('Test Block')->setClass('Oro\\Bundle\\UserBundle\\Entity\\User')->setPriority(1);
     $subblocks = array();
     $subblocksArray = array();
     foreach ($this->testSubBlocksConfig as $code => $data) {
         $subBlock = new SubBlockConfig($code);
         $subBlock->setTitle($data['title'])->setPriority($data['priority']);
         $blockConfig->addSubBlock($subBlock);
         $subblocks[] = $subBlock;
         $subblocksArray[] = $subBlock->toArray();
     }
     $this->formConfig->addBlock($blockConfig);
     $this->blocks[] = $blockConfig;
     /** test hasBlock */
     $this->assertTrue($this->formConfig->hasBlock('testBlock'));
     /** test getBlock */
     $this->assertEquals($blockConfig, $this->formConfig->getBlock('testBlock'));
     /** test getSubBlock */
     $this->assertEquals($subblocks[0], $this->formConfig->getSubBlocks('testBlock', 'common'));
     /** test toArray() */
     $this->assertEquals(array(array('title' => 'Test Block', 'class' => 'Oro\\Bundle\\UserBundle\\Entity\\User', 'subblocks' => $subblocksArray, 'description' => null)), $this->formConfig->toArray());
     /** test getBlocks */
     $this->formConfig->setBlocks($this->blocks);
     $this->assertEquals($this->blocks, $this->formConfig->getBlocks());
 }
Esempio n. 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;
 }
Esempio n. 3
0
 /**
  * @param BlockConfig $block
  * @return $this
  */
 public function addBlock(BlockConfig $block)
 {
     $this->blocks[$block->getCode()] = $block;
     $this->sortBlocks();
     return $this;
 }
Esempio n. 4
0
 /**
  * @param BlockConfig $block
  * @param string      $code
  * @param array       $config
  *
  * @return SubBlockConfig
  */
 protected function addSubBlock(BlockConfig $block, $code, $config = [])
 {
     if ($block->hasSubBlock($code)) {
         $subBlock = $block->getSubBlock($code);
     } else {
         $subBlock = new SubBlockConfig($code);
     }
     if ($this->hasValue($config, 'title')) {
         $subBlock->setTitle($config['title']);
     }
     if ($this->hasValue($config, 'description')) {
         $subBlock->setDescription($config['description']);
     }
     if ($this->hasValue($config, 'priority')) {
         $subBlock->setPriority($config['priority']);
     }
     if ($this->hasValue($config, 'useSpan')) {
         $subBlock->setUseSpan($config['useSpan']);
     }
     $block->addSubBlock($subBlock);
     return $subBlock;
 }
 public function testBlockConfig()
 {
     $this->assertNull($this->blockConfig->getBlockConfig());
     $this->blockConfig->setBlockConfig($this->testBlockConfig);
     $this->assertEquals($this->testBlockConfig, $this->readAttribute($this->blockConfig, 'blockConfig'));
 }