/** * {@inheritdoc} */ public function load($configuration) { $block = new Block(); $block->setId(uniqid()); $block->setType($configuration['type']); $block->setSettings($this->getSettings($configuration)); $block->setEnabled(true); $block->setCreatedAt(new \DateTime()); $block->setUpdatedAt(new \DateTime()); return $block; }
/** * {@inheritdoc} */ public function load($configuration) { if (!in_array($configuration['type'], $this->types)) { throw new \RuntimeException(sprintf('The block type "%s" does not exist', $configuration['type'])); } $block = new Block(); $block->setId(uniqid()); $block->setType($configuration['type']); $block->setEnabled(true); $block->setCreatedAt(new \DateTime()); $block->setUpdatedAt(new \DateTime()); $block->setSettings(isset($configuration['settings']) ? $configuration['settings'] : array()); return $block; }
public function testSetterGetter() { $time = new \DateTime(); $parent = $this->getMockBuilder('Sonata\\BlockBundle\\Model\\Block')->getMock(); $block = new Block(); $block->setCreatedAt($time); $block->setUpdatedAt($time); $block->setEnabled(true); $block->setPosition(1); $block->setType('foo.bar'); $block->setParent($parent); $this->assertEquals($time, $block->getCreatedAt()); $this->assertEquals($time, $block->getUpdatedAt()); $this->assertTrue($block->getEnabled()); $this->assertEquals(1, $block->getPosition()); $this->assertEquals('foo.bar', $block->getType()); $this->assertEquals($parent, $block->getParent()); }