/** * 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); }
/** * Test * * @return void */ public function testFromFakeUrlKey() { $model = Model::fromUrlKey($this->object->getUrlKey(), 1000); $this->assertFalse($model); }
/** * Render children * * @param Document\Model $document Document model * @param string $parentUrl Parent url * @param array &$data Array * * @return void */ protected function renderChildren($document, $parentUrl, &$data) { $children = $document->getChildren(); if (!empty($children) && is_array($children)) { $data['pages'] = $this->render($children, (empty($parentUrl) ? null : $parentUrl . '/') . $document->getUrlKey()); if ($this->useActiveBranch()) { $data['active'] = ($data['active'] or $this->hasActiveChildren($data['pages'])); } } }