/** * Initialise form fields * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareForm() { /* * Checking if user have permissions to save information */ $isElementDisabled = !$this->_isAllowedAction('Magento_Cms::save'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(array('data' => array('html_id_prefix' => 'page_'))); $model = $this->_coreRegistry->registry('cms_page'); $layoutFieldset = $form->addFieldset('layout_fieldset', array('legend' => __('Page Layout'), 'class' => 'fieldset-wide', 'disabled' => $isElementDisabled)); $layoutFieldset->addField('root_template', 'select', array('name' => 'root_template', 'label' => __('Layout'), 'required' => true, 'values' => $this->_pageLayout->toOptionArray(), 'disabled' => $isElementDisabled)); if (!$model->getId()) { $model->setRootTemplate($this->_pageLayout->getDefaultValue()); } $layoutFieldset->addField('layout_update_xml', 'textarea', array('name' => 'layout_update_xml', 'label' => __('Layout Update XML'), 'style' => 'height:24em;', 'disabled' => $isElementDisabled)); $designFieldset = $form->addFieldset('design_fieldset', array('legend' => __('Custom Design'), 'class' => 'fieldset-wide', 'disabled' => $isElementDisabled)); $dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT); $designFieldset->addField('custom_theme_from', 'date', array('name' => 'custom_theme_from', 'label' => __('Custom Design From'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'date_format' => $dateFormat, 'disabled' => $isElementDisabled, 'class' => 'validate-date validate-date-range date-range-custom_theme-from')); $designFieldset->addField('custom_theme_to', 'date', array('name' => 'custom_theme_to', 'label' => __('Custom Design To'), 'image' => $this->getViewFileUrl('images/grid-cal.gif'), 'date_format' => $dateFormat, 'disabled' => $isElementDisabled, 'class' => 'validate-date validate-date-range date-range-custom_theme-to')); $options = $this->_labelFactory->create()->getLabelsCollection(__('-- Please Select --')); $designFieldset->addField('custom_theme', 'select', array('name' => 'custom_theme', 'label' => __('Custom Theme'), 'values' => $options, 'disabled' => $isElementDisabled)); $designFieldset->addField('custom_root_template', 'select', array('name' => 'custom_root_template', 'label' => __('Custom Layout'), 'values' => $this->_pageLayout->toOptionArray(true), 'disabled' => $isElementDisabled)); $designFieldset->addField('custom_layout_update_xml', 'textarea', array('name' => 'custom_layout_update_xml', 'label' => __('Custom Layout Update XML'), 'style' => 'height:24em;', 'disabled' => $isElementDisabled)); $this->_eventManager->dispatch('adminhtml_cms_page_edit_tab_design_prepare_form', array('form' => $form)); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * @test * @return void * @covers \Magento\Theme\Model\Layout\Source\Layout::toOptionArray * @covers \Magento\Theme\Model\Layout\Source\Layout::getOptions * @covers \Magento\Theme\Model\Layout\Source\Layout::getDefaultValue * @covers \Magento\Theme\Model\Layout\Source\Layout::__construct */ public function testToOptionArray() { $data = ['code' => 'testCode', 'label' => 'testLabel', 'is_default' => true]; $expectedResult = [['value' => '', 'label' => __('-- Please Select --')], ['value' => 'testCode', 'label' => 'testLabel']]; $this->config->expects($this->once())->method('getPageLayouts')->willReturn([new Object($data)]); $this->assertEquals($expectedResult, $this->_model->toOptionArray(true)); $this->assertEquals('testCode', $this->_model->getDefaultValue()); }
/** * {@inheritdoc} */ public function getAllOptions() { if (!$this->_options) { $this->_options = $this->_pageSourceLayout->toOptionArray(); array_unshift($this->_options, array('value' => '', 'label' => __('No layout updates'))); } return $this->_options; }