/** * Load the record */ private function loadData() { // get data $this->selectedTheme = $this->getParameter('theme', 'string'); // build available themes foreach (BackendExtensionsModel::getThemes() as $theme) { $this->availableThemes[$theme['value']] = $theme['label']; } // determine selected theme, based upon submitted form or default theme $this->selectedTheme = SpoonFilter::getValue($this->selectedTheme, array_keys($this->availableThemes), BackendModel::getModuleSetting('core', 'theme', 'core')); }
/** * Load the form */ private function loadForm() { // create form $this->frm = new BackendForm('edit'); // init var $defaultId = BackendModel::getModuleSetting('pages', 'default_template'); // build available themes $themes = array(); foreach (BackendExtensionsModel::getThemes() as $theme) { $themes[$theme['value']] = $theme['label']; } // create elements $this->frm->addDropdown('theme', $themes, BackendModel::getModuleSetting('core', 'theme', 'core')); $this->frm->addText('label', $this->record['label']); $this->frm->addText('file', str_replace('core/layout/templates/', '', $this->record['path'])); $this->frm->addTextarea('format', str_replace('],[', "],\n[", $this->record['data']['format'])); $this->frm->addCheckbox('active', $this->record['active'] == 'Y'); $this->frm->addCheckbox('default', $this->record['id'] == $defaultId); $this->frm->addCheckbox('overwrite', false); // if this is the default template we can't alter the active/default state if ($this->record['id'] == $defaultId) { $this->frm->getField('active')->setAttributes(array('disabled' => 'disabled')); $this->frm->getField('default')->setAttributes(array('disabled' => 'disabled')); } // if the template is in use we cant alter the active state if (BackendExtensionsModel::isTemplateInUse($this->id)) { $this->frm->getField('active')->setAttributes(array('disabled' => 'disabled')); } // init vars $positions = array(); $blocks = array(); $widgets = array(); $extras = BackendExtensionsModel::getExtras(); // loop extras to populate the default extras foreach ($extras as $item) { if ($item['type'] == 'block') { $blocks[$item['id']] = SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $blocks[$item['id']] = SpoonFilter::ucfirst($item['data']['extra_label']); } } elseif ($item['type'] == 'widget') { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . SpoonFilter::ucfirst(BL::lbl($item['label'])); if (isset($item['data']['extra_label'])) { $widgets[$item['id']] = SpoonFilter::ucfirst(BL::lbl(SpoonFilter::toCamelCase($item['module']))) . ': ' . $item['data']['extra_label']; } } } // sort asort($blocks, SORT_STRING); asort($widgets, SORT_STRING); // create array $defaultExtras = array('' => array(0 => SpoonFilter::ucfirst(BL::lbl('Editor'))), SpoonFilter::ucfirst(BL::lbl('Widgets')) => $widgets); // create default position field $position = array(); $position['i'] = 0; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], null, 255, 'inputText positionName', 'inputTextError positionName'); $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . 0, $defaultExtras, null, false, 'positionBlock', 'positionBlockError'); $positions[] = $position; // content has been submitted: re-create submitted content rather than the db-fetched content if (isset($_POST['position_0'])) { // init vars $this->names = array(); $this->extras = array(); $i = 1; $errors = array(); // loop submitted positions while (isset($_POST['position_' . $i])) { // init vars $j = 0; $extras = array(); // gather position names $name = $_POST['position_' . $i]; // loop submitted blocks while (isset($_POST['type_' . $i . '_' . $j])) { // gather blocks id $extras[] = (int) $_POST['type_' . $i . '_' . $j]; // increment counter; go fetch next block $j++; } // increment counter; go fetch next position $i++; // position already exists -> error if (in_array($name, $this->names)) { $errors[] = sprintf(BL::getError('DuplicatePositionName'), $name); } // position name == fallback -> error if ($name == 'fallback') { $errors[] = sprintf(BL::getError('ReservedPositionName'), $name); } // not alphanumeric -> error if (!SpoonFilter::isValidAgainstRegexp('/^[a-z0-9]+$/i', $name)) { $errors[] = sprintf(BL::getError('NoAlphaNumPositionName'), $name); } // save positions $this->names[] = $name; $this->extras[$name] = $extras; } // add errors if ($errors) { $this->frm->addError(implode('<br />', array_unique($errors))); } } // build blocks array foreach ($this->names as $i => $name) { // create default position field $position = array(); $position['i'] = $i + 1; $position['formElements']['txtPosition'] = $this->frm->addText('position_' . $position['i'], $name, 255, 'inputText positionName', 'inputTextError positionName'); if (isset($this->extras[$name])) { foreach ($this->extras[$name] as $y => $extra) { $position['blocks'][]['formElements']['ddmType'] = $this->frm->addDropdown('type_' . $position['i'] . '_' . $y, $defaultExtras, $extra, false, 'positionBlock', 'positionBlockError'); } } $positions[] = $position; } // assign $this->tpl->assign('positions', $positions); }