/** * Initialize General sub form * * @return Config */ public function initGeneral() { //General settings $generalFieldset = new Fieldset('general'); $generalFieldset->setLabel('General'); $name = new Element\Text('site_name'); $name->setLabel('Site name')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('id', 'site_name')->setAttribute('class', 'form-control'); $generalFieldset->add($name); $this->getInputFilter()->add(array('name' => 'site_name', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'site_name'); $isOffline = new Element\Checkbox('site_is_offline'); $isOffline->setLabel('Is offline')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'input-checkbox')->setAttribute('id', 'site-offiline')->setCheckedValue('1'); $generalFieldset->add($isOffline); $this->getInputFilter()->add(array('name' => 'site_is_offline', 'required' => false), 'site_is_offline'); $documentCollection = new Document\Collection(); $documentCollection->load(0); $offlineDocument = new Element\Select('site_offline_document'); $offlineDocument->setLabel('Offline document')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_offline_document')->setValueOptions(array('Select document') + $documentCollection->getSelect()); $generalFieldset->add($offlineDocument); $this->getInputFilter()->add(array('name' => 'site_offline_document', 'required' => true), 'site_offline_document'); $layoutCollection = new Layout\Collection(); $layoutNotFound = new Element\Select('site_404_layout'); $layoutNotFound->setLabel('404 layout')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_404_layout')->setValueOptions(array('Select document') + $layoutCollection->getSelect()); $generalFieldset->add($layoutNotFound); $this->getInputFilter()->add(array('name' => 'site_404_layout', 'required' => true), 'site_404_layout'); $layoutException = new Element\Select('site_exception_layout'); $layoutException->setLabel('Exception layout')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_exception_layout')->setValueOptions(array('Select document') + $layoutCollection->getSelect()); $generalFieldset->add($layoutException); $this->getInputFilter()->add(array('name' => 'site_exception_layout', 'required' => true), 'site_exception_layout'); $this->add($generalFieldset); return $this; }
/** * Load document form from DocumentModel * * @param DocumentModel $document Document model * @param array $config Configuration * * @return void */ public function load(DocumentModel $document, array $config) { $this->get('document-name')->setValue($document->getName()); $this->get('document-url_key')->setValue($document->getUrlKey()); $status = new Element\Checkbox('document-status'); $status->setLabel('Publish')->setValue($document->isPublished())->setAttribute('id', 'status')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($status); $showInNav = new Element\Checkbox('document-show_in_nav'); $showInNav->setLabel('Show in nav')->setValue($document->showInNav())->setAttribute('id', 'show_in_nav')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($showInNav); $canBeCached = new Element\Checkbox('document-can_be_cached'); $canBeCached->setLabel('Can be cached')->setValue($document->canBeCached())->setAttribute('id', 'can_be_cached')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($canBeCached); array_unshift($config['locales'], '-- Use parent configuration'); $locale = new Element\Select('document-locale'); $locale->setLabel('Locale')->setValueOptions($config['locales'])->setValue($document->getLocale())->setAttribute('id', 'locale')->setAttribute('class', 'form-control'); $this->add($locale); $documentType = $document->getDocumentType(); $viewsCollection = $documentType->getAvailableViews(); $select = $viewsCollection->getSelect(); $viewSelected = $document->getViewId(); $viewModel = View\Model::fromId($document->getDocumentType()->getDefaultViewId()); if (!empty($viewModel)) { $select = $select + array($viewModel->getId() => $viewModel->getName()); if (empty($viewSelected)) { $viewSelected = $viewModel->getId(); } } $view = new Element\Select('document-view'); $view->setValueOptions($select)->setValue((string) $viewSelected)->setAttribute('id', 'view')->setAttribute('class', 'form-control')->setLabel('View'); $inputFilterFactory = $this->getInputFilter(); $inputFilterFactory->add(array('name' => 'document-view', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-view'); $this->add($view); $layoutsCollection = new Layout\Collection(); $layout = new Element\Select('document-layout'); $layout->setValueOptions($layoutsCollection->getSelect())->setValue((string) $document->getLayoutId())->setAttribute('id', 'layout')->setAttribute('class', 'form-control')->setLabel('Layout'); $inputFilterFactory->add(array('name' => 'document-layout', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-layout'); $this->add($layout); $this->remove('document_type'); $this->remove('parent'); $moreInformation = new Element\Hidden('more_information'); $moreInformation->setAttribute('content', ''); $this->add($moreInformation); $this->parentId = $document->getParentId(); $this->documentId = $document->getId(); $this->loadValues($document); }