/** * Changes the order and placement of the controllers by * post data that was submitted a long with the form * * @return bool */ protected function updateOrder() { try { $layout = new Layout($this->_input->post('content_layout_name')); // Update all of the controllers attributes $updated = 0; foreach ($this->_input->post('content_layout') as $cid => $details) { try { $cntrlr = $layout->getControllerDetails($cid); $cntrlr['order'] = abs($details['order']); $cntrlr['sector'] = $details['sector']; $layout->editController($cntrlr['id'], $cntrlr); $updated++; } catch (Layout_ControllerNoExist $e) { } } if ($layout->save()) { if ($updated > 0) { $this->_event->success(sprintf(t('Updated order and placement for layout "%s"'), $layout->getName())); } } else { $this->_event->error(t('Unable to save layout, ensure file is writable')); } } catch (Input_KeyNoExist $e) { } return true; }
/** * Upgrades to 2.4.0-rc1 (2.3.90) * * @return bool|string */ protected function upgradeTo_240_rc1() { switch ($this->version) { case '2.3.80': foreach (Layout::getAll() as $layout) { $layoutObj = new Layout($layout['name']); foreach ($layoutObj->getControllers() as $cntrlr) { if ($cntrlr['mod'] == 'media' && $cntrlr['con'] == 'index' && $cntrlr['sec'] == 'latest') { $cntrlr['sec'] = 'cat'; $cntrlr['config']['display_cat'] = ''; $layoutObj->editController($cntrlr['id'], $cntrlr); } } $layoutObj->save(); } case '2.3.81': return '2.3.90'; default: return '2.3.90'; } }
/** * Allows the user to configure the module that is attached to a * sector. This, however, currently depends on JavaScript enabled. * * @return string */ public function indexSection($layoutName = null) { $this->setTitle(t('Edit module')); $this->setOutputType(self::_OT_CONFIG); // Check permission and if a layout has been provided if (!$this->_acl->check('content_layout_config_module')) { throw new Module_NoPermission(); } else { if ($layoutName === null) { $this->_event->error(t('Unable to edit attached module, no layout given')); return zula_redirect($this->_router->makeUrl('content_layout')); } } // Get correct cntrlr ID that is to be edited try { $cntrlrId = $this->_router->getArgument('id'); } catch (Router_ArgNoExist $e) { try { $cntrlrId = $this->_input->post('content_layout/cid'); } catch (Input_KeyNoExist $e) { $this->_event->error(t('Unable to edit attached module, no ID given')); return zula_redirect($this->_router->makeUrl('content_layout')); } } // Create the correct layout and ensure cntrlr exists $layout = new Layout($layoutName); try { $cntrlr = $layout->getControllerDetails($cntrlrId); $module = new Module($cntrlr['mod']); $this->setTitle(sprintf(t('Configure attached module "%1$s"'), $module->title)); if (!isset($cntrlr['config']['clDescription'])) { $cntrlr['config']['clDescription'] = ''; } } catch (Layout_ControllerNoExist $e) { $this->_event->error(sprintf(t('Unable to edit controller "%1$d" as it does not exist'), $cntrlrId)); return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName)); } catch (Module_NoExist $e) { $this->_event->error(sprintf(t('Unable to edit attached module "%1$s" as it does not exist'), $cntrlr['mod'])); return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layoutName)); } /** * Prepare form validation */ $form = new View_form('edit/module.html', $this->getDetail('name'), false); $form->addElement('content_layout/config/displayTitle', $cntrlr['config']['displayTitle'], t('Display Title'), new Validator_InArray(array('true', 'false', 'custom'))); $form->addElement('content_layout/config/customTitle', $cntrlr['config']['customTitle'], t('Custom title'), new Validator_Length(0, 255)); $form->addElement('content_layout/config/htmlWrapClass', $cntrlr['config']['htmlWrapClass'], t('HTML class'), new Validator_Length(0, 500), $cntrlr['sector'] != 'SC'); $form->addElement('content_layout/config/clDescription', $cntrlr['config']['clDescription'], t('Description'), new Validator_Length(0, 255), $cntrlr['sector'] != 'SC'); $form->addElement('content_layout/cntrlr', null, t('Controller'), new Validator_Alphanumeric('_-.!+')); $form->addElement('content_layout/section', null, t('Section'), new Validator_Alphanumeric('_-.!+')); $form->addElement('content_layout/config', null, t('Config'), new Validator_Is('array'), false); if ($form->hasInput() && $form->isValid()) { $fd = $form->getValues('content_layout'); try { $layout->editController($cntrlr['id'], array('con' => $fd['cntrlr'], 'sec' => $fd['section'], 'order' => $cntrlr['order'], 'config' => isset($fd['config']) ? $fd['config'] : array())); try { $roles = $this->_input->post('acl_resources/layout_controller_' . $cntrlr['id']); } catch (Input_ValueNoExist $e) { $roles = array(); } $this->_acl->allowOnly('layout_controller_' . $cntrlr['id'], $roles); if ($layout->save()) { $this->_event->success(sprintf(t('Configured attached module ID "%d"'), $cntrlr['id'])); } else { $this->_event->error(t('Unable to save layout, ensure file is writable')); } } catch (Layout_ControllerNoExist $e) { $this->_event->error(sprintf(t('Unable to edit attached module ID "%d" as it does not exist'), $cntrlr['id'])); } catch (Theme_SectorMapNotWriteable $e) { $this->_event->error(sprintf(t('Unable to edit module in sector map: $s'), $e->getMessage())); } // Redirect back to correct location, FPSC layouts go back to index $url = new Router_Url('content_layout'); $url->siteType($this->_router->getSiteType()); if (strpos($layoutName, 'fpsc-') === 0) { $url->queryArgs(array('type' => substr($layoutName, 5))); } else { $url->controller('manage')->section($layoutName); } return zula_redirect($url); } /** * Gets all displays modes that this module offers, the current display * mode being used - once done start building up the form. */ $displayModes = Hooks::notifyAll($module->name . '_display_modes'); $currentMode = Hooks::notifyAll($module->name . '_resolve_mode', $cntrlr['con'], $cntrlr['sec'], $cntrlr['config']); $this->addAsset('js/edit.js'); $form->assign(array('CID' => $cntrlr['id'], 'LAYOUT_NAME' => $layoutName, 'SECTOR' => $cntrlr['sector'], 'MODULE' => $module->getDetails(), 'DISPLAY_MODES' => empty($displayModes) ? array('default' => t('Default')) : $displayModes, 'CURRENT_MODE' => empty($currentMode) ? 'default' : $currentMode[0])); $jsConfig = array_merge($cntrlr, $cntrlr['config']); unset($jsConfig['config']); $form->assignHtml(array('JS_CONFIG' => zula_array_js_string($jsConfig), 'ACL_FORM' => $this->_acl->buildForm(array(t('View attached module') => 'layout_controller_' . $cntrlr['id'])))); return $form->getOutput(); }