_dfRelations = $this->getConfigArray('dfRelations'); return parent::init(); } public function setBlockSize(array $size) { if (!array_key_exists('width', $size) || empty($size['width'])) { throw new Exception('Block width is unknown'); } if (!array_key_exists('height', $size) || empty($size['height'])) { throw new Exception('Block height is unknown'); } $this->_blockSize = $size; return $this; } public function getBlockSize($string = false) { if ($string) { if (!empty($this->_blockSize)) { return $this->_blockSize['width'] . 'x' . $this->_blockSize['height']; } return false; } return $this->_blockSize; } protected function _initElements() { $this->addElement('text', 'title', ['label' => 'Title', 'required' => true]); $this->addElement( 'select', 'type', [ 'label' => 'Item type', 'required' => true, 'multiOptions' => [Obj::TYPE_IMAGE => 'Image', Obj::TYPE_VIDEO => 'Video'], ] ); $this->addElement('htmlEditor', 'content', ['label' => 'Content', 'toolbar' => 'Basic']); $resize = $this->getBlockSize(true); $image = $this->getConfigArray('image'); if (!array_key_exists($resize, $image)) { throw new Exception('Unknown block size'); } $this->addElement( 'extendedImage', 'image', [ 'label' => 'Image', 'required' => (Obj::TYPE_IMAGE == $this->_getData('type')), 'resize' => $image[$resize], ] ); $this->getElement('image')->getDecorator('label')->setOption('class', 'required'); $this->addElement('url', 'url', ['label' => 'URL']); $this->addElement( 'media', 'video', [ 'label' => 'Video', 'required' => (Obj::TYPE_VIDEO == $this->_getData('type')), ] ); $this->getElement('video')->getDecorator('label')->setOption('class', 'required'); return $this; } }