private function loadForm()
{
// get default template id
$defaultTemplateId = $this->get('fork.settings')->get('Pages', 'default_template', 1);
// create form
$this->frm = new BackendForm('edit');
// assign in template
$this->tpl->assign('defaultTemplateId', $defaultTemplateId);
// create elements
$this->frm->addText('title', $this->record['title'], null, 'form-control title', 'form-control danger title');
$this->frm->addEditor('html');
$this->frm->addHidden('template_id', $this->record['template_id']);
$this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), $this->record['hidden']);
// image related fields
$this->frm->addImage('image');
$this->frm->addCheckbox('remove_image');
// page auth related fields
// check if profiles module is installed
if (BackendModel::isModuleInstalled('Profiles')) {
// add checkbox for auth_required
$this->frm->addCheckbox('auth_required', isset($this->record['data']['auth_required']) && $this->record['data']['auth_required']);
// get all groups and parse them in key value pair
$groupItems = BackendProfilesModel::getGroups();
if (!empty($groupItems)) {
$groups = array();
foreach ($groupItems as $key => $item) {
$groups[] = array('label' => $item, 'value' => $key);
}
// set checked values
$checkedGroups = array();
if (is_array($this->record['data']['auth_groups'])) {
foreach ($this->record['data']['auth_groups'] as $group) {
$checkedGroups[] = $group;
}
}
// add multi checkbox
$this->frm->addMultiCheckbox('auth_groups', $groups, $checkedGroups);
}
}
// a god user should be able to adjust the detailed settings for a page easily
if ($this->isGod) {
// init some vars
$items = array('move', 'children', 'edit', 'delete');
$checked = array();
$values = array();
foreach ($items as $value) {
$values[] = array('label' => BL::msg(\SpoonFilter::toCamelCase('allow_' . $value)), 'value' => $value);
if (isset($this->record['allow_' . $value]) && $this->record['allow_' . $value] == 'Y') {
$checked[] = $value;
}
}
$this->frm->addMultiCheckbox('allow', $values, $checked);
}
// build prototype block
$block['index'] = 0;
$block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], true);
$block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], 0);
$block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], 'fallback');
$block['formElements']['txtHTML'] = $this->frm->addTextarea('block_html_' . $block['index'], '');
// this is no editor; we'll add the editor in JS
// add default block to "fallback" position, the only one which we can rest assured to exist
$this->positions['fallback']['blocks'][] = $block;
// content has been submitted: re-create submitted content rather than the db-fetched content
if (isset($_POST['block_html_0'])) {
// init vars
$this->blocksContent = array();
$hasBlock = false;
$i = 1;
// loop submitted blocks
while (isset($_POST['block_position_' . $i])) {
// init var
$block = array();
// save block position
$block['position'] = $_POST['block_position_' . $i];
$positions[$block['position']][] = $block;
// set linked extra
$block['extra_id'] = $_POST['block_extra_id_' . $i];
// reset some stuff
if ($block['extra_id'] <= 0) {
$block['extra_id'] = null;
}
// init html
$block['html'] = null;
// extra-type is HTML
if ($block['extra_id'] === null) {
// reset vars
$block['extra_id'] = null;
$block['html'] = $_POST['block_html_' . $i];
} else {
// type of block
if (isset($this->extras[$block['extra_id']]['type']) && $this->extras[$block['extra_id']]['type'] == 'block') {
// set error
if ($hasBlock) {
$this->frm->addError(BL::err('CantAdd2Blocks'));
}
// home can't have blocks
if ($this->record['id'] == 1) {
$this->frm->addError(BL::err('HomeCantHaveBlocks'));
}
// reset var
$hasBlock = true;
}
}
// set data
$block['created_on'] = BackendModel::getUTCDate();
$block['edited_on'] = $block['created_on'];
$block['visible'] = isset($_POST['block_visible_' . $i]) && $_POST['block_visible_' . $i] == 'Y' ? 'Y' : 'N';
$block['sequence'] = count($positions[$block['position']]) - 1;
// add to blocks
$this->blocksContent[] = $block;
// increment counter; go fetch next block
++$i;
}
}
// build blocks array
foreach ($this->blocksContent as $i => $block) {
$block['index'] = $i + 1;
$block['formElements']['chkVisible'] = $this->frm->addCheckbox('block_visible_' . $block['index'], $block['visible'] == 'Y');
$block['formElements']['hidExtraId'] = $this->frm->addHidden('block_extra_id_' . $block['index'], (int) $block['extra_id']);
$block['formElements']['hidPosition'] = $this->frm->addHidden('block_position_' . $block['index'], $block['position']);
$block['formElements']['txtHTML'] = $this->frm->addTextarea('block_html_' . $block['index'], $block['html']);
// this is no editor; we'll add the editor in JS
$this->positions[$block['position']]['blocks'][] = $block;
}
// redirect
$redirectValue = 'none';
if (isset($this->record['data']['internal_redirect']['page_id'])) {
$redirectValue = 'internal';
}
if (isset($this->record['data']['external_redirect']['url'])) {
$redirectValue = 'external';
}
$redirectValues = array(array('value' => 'none', 'label' => \SpoonFilter::ucfirst(BL::lbl('None'))), array('value' => 'internal', 'label' => \SpoonFilter::ucfirst(BL::lbl('InternalLink')), 'variables' => array('isInternal' => true)), array('value' => 'external', 'label' => \SpoonFilter::ucfirst(BL::lbl('ExternalLink')), 'variables' => array('isExternal' => true)));
$this->frm->addRadiobutton('redirect', $redirectValues, $redirectValue);
$this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown(), $redirectValue == 'internal' ? $this->record['data']['internal_redirect']['page_id'] : null);
$this->frm->addText('external_redirect', $redirectValue == 'external' ? urldecode($this->record['data']['external_redirect']['url']) : null, null, null, null, true);
// page info
$this->frm->addCheckbox('navigation_title_overwrite', $this->record['navigation_title_overwrite'] == 'Y');
$this->frm->addText('navigation_title', $this->record['navigation_title']);
if ($this->showTags()) {
// tags
$this->frm->addText('tags', BackendTagsModel::getTags($this->URL->getModule(), $this->id), null, 'form-control js-tags-input', 'error js-tags-input');
}
// a specific action
$isAction = isset($this->record['data']['is_action']) && $this->record['data']['is_action'] == true ? true : false;
$this->frm->addCheckbox('is_action', $isAction);
// extra
$blockTypes = BackendPagesModel::getTypes();
$this->frm->addDropdown('extra_type', $blockTypes, key($blockTypes));
// meta
$this->meta = new BackendMeta($this->frm, $this->record['meta_id'], 'title', true);
// set callback for generating an unique URL
$this->meta->setURLCallback('Backend\\Modules\\Pages\\Engine\\Model', 'getURL', array($this->record['id'], $this->record['parent_id'], $isAction));
}