private function loadForm()
{
// get default template id
$defaultTemplateId = $this->get('fork.settings')->get('Pages', 'default_template', 1);
// create form
$this->frm = new BackendForm('add');
// assign in template
$this->tpl->assign('defaultTemplateId', $defaultTemplateId);
// create elements
$this->frm->addText('title', null, null, 'form-control title', 'form-control danger title');
$this->frm->addEditor('html');
$this->frm->addHidden('template_id', $defaultTemplateId);
$this->frm->addRadiobutton('hidden', array(array('label' => BL::lbl('Hidden'), 'value' => 'Y'), array('label' => BL::lbl('Published'), 'value' => 'N')), 'N');
// image related fields
$this->frm->addImage('image');
// a god user should be able to adjust the detailed settings for a page easily
if ($this->isGod) {
// init some vars
$items = array('move' => true, 'children' => true, 'edit' => true, 'delete' => true);
$checked = array();
$values = array();
foreach ($items as $value => $itemIsChecked) {
$values[] = array('label' => BL::msg(\SpoonFilter::toCamelCase('allow_' . $value)), 'value' => $value);
if ($itemIsChecked) {
$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'));
}
// 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
$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, 'none');
$this->frm->addDropdown('internal_redirect', BackendPagesModel::getPagesForDropdown());
$this->frm->addText('external_redirect', null, null, null, null, true);
// page info
$this->frm->addCheckbox('navigation_title_overwrite');
$this->frm->addText('navigation_title');
if ($this->showTags()) {
// tags
$this->frm->addText('tags', null, null, 'form-control js-tags-input', 'form-control danger js-tags-input');
}
// a specific action
$this->frm->addCheckbox('is_action', false);
// extra
$blockTypes = BackendPagesModel::getTypes();
$this->frm->addDropdown('extra_type', $blockTypes, key($blockTypes));
// meta
$this->meta = new BackendMeta($this->frm, null, 'title', true);
// set callback for generating an unique URL
$this->meta->setURLCallback('Backend\\Modules\\Pages\\Engine\\Model', 'getURL', array(0, null, false));
}