Commit 75e30c56 authored by Tino Goratsch's avatar Tino Goratsch

some more code simplifications

parent 22532a1a
......@@ -109,6 +109,19 @@ class Forms
return $select;
}
/**
* @param string $name
* @param string $currentValue
* @param string $selected
*
* @return array
*/
public function linkTargetSelectGenerator($name, $currentValue = '', $selected = '')
{
$langTarget = [$this->lang->t('system', 'window_self'), $this->lang->t('system', 'window_blank')];
return $this->selectGenerator($name, [1, 2], $langTarget, $currentValue, $selected);
}
/**
* @param string $name
* @param string $currentValue
......
......@@ -94,15 +94,9 @@ class Items extends Core\Modules\AdminController
$this->_createPost($this->request->getPost()->getAll());
}
// Seitentyp
$this->view->assign('mode', $this->fetchMenuItemModes());
// Module
$this->view->assign('modules', $this->fetchModules());
// Ziel des Hyperlinks
$lang_target = [$this->lang->t('system', 'window_self'), $this->lang->t('system', 'window_blank')];
$this->view->assign('target', $this->get('core.helpers.forms')->selectGenerator('target', [1, 2], $lang_target));
$this->view->assign('target', $this->get('core.helpers.forms')->linkTargetSelectGenerator('target'));
if ($this->articlesHelpers) {
$this->view->assign('articles', $this->articlesHelpers->articlesList());
......@@ -169,15 +163,9 @@ class Items extends Core\Modules\AdminController
$this->_editPost($this->request->getPost()->getAll(), $menuItem, $id);
}
// Seitentyp
$this->view->assign('mode', $this->fetchMenuItemModes($menuItem['mode']));
// Module
$this->view->assign('modules', $this->fetchModules($menuItem));
// Ziel des Hyperlinks
$lang_target = [$this->lang->t('system', 'window_self'), $this->lang->t('system', 'window_blank')];
$this->view->assign('target', $this->get('core.helpers.forms')->selectGenerator('target', [1, 2], $lang_target, $menuItem['target']));
$this->view->assign('target', $this->get('core.helpers.forms')->linkTargetSelectGenerator('target', $menuItem['target']));
if ($this->articlesHelpers) {
$matches = [];
......
......@@ -90,33 +90,9 @@ class Index extends Core\Modules\AdminController
$this->_createPost($this->request->getPost()->getAll(), $settings);
}
// Kategorien
$this->view->assign('categories', $this->categoriesHelpers->categoriesList('news', '', true));
// Weiterlesen & Kommentare
if ($settings['readmore'] == 1 || ($settings['comments'] == 1 && $this->modules->isActive('comments') === true)) {
$options = [];
if ($settings['readmore'] == 1) {
$options[] = [
'name' => 'readmore',
'checked' => $this->get('core.helpers.forms')->selectEntry('readmore', '1', '0', 'checked'),
'lang' => $this->lang->t('news', 'activate_readmore')
];
}
if ($settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
$options[] = [
'name' => 'comments',
'checked' => $this->get('core.helpers.forms')->selectEntry('comments', '1', '0', 'checked'),
'lang' => $this->lang->t('system', 'allow_comments')
];
}
$this->view->assign('options', $options);
}
// Linkziel
$lang_target = [$this->lang->t('system', 'window_self'), $this->lang->t('system', 'window_blank')];
$this->view->assign('target', $this->get('core.helpers.forms')->selectGenerator('target', [1, 2], $lang_target));
$this->view->assign('options', $this->fetchNewsOptions($settings, 0, 0));
$this->view->assign('target', $this->get('core.helpers.forms')->linkTargetSelectGenerator('target'));
$this->view->assign('SEO_FORM_FIELDS', $this->seo->formFields());
$defaults = [
......@@ -142,7 +118,7 @@ class Index extends Core\Modules\AdminController
$this->actionHelper->handleDeleteAction(
$this,
$action,
function($items) {
function ($items) {
$bool = false;
foreach ($items as $item) {
......@@ -178,35 +154,12 @@ class Index extends Core\Modules\AdminController
$this->_editPost($this->request->getPost()->getAll(), $settings, $id);
}
// Kategorien
$this->view->assign('categories', $this->categoriesHelpers->categoriesList('news', $news['category_id'], true));
$this->view->assign('options', $this->fetchNewsOptions($settings, $news['readmore'], $news['comments']));
// Weiterlesen & Kommentare
if ($settings['readmore'] == 1 || ($settings['comments'] == 1 && $this->modules->isActive('comments') === true)) {
$options = [];
if ($settings['readmore'] == 1) {
$options[] = [
'name' => 'readmore',
'checked' => $this->get('core.helpers.forms')->selectEntry('readmore', '1', $news['readmore'], 'checked'),
'lang' => $this->lang->t('news', 'activate_readmore')
];
}
if ($settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
$options[] = [
'name' => 'comments',
'checked' => $this->get('core.helpers.forms')->selectEntry('comments', '1', $news['comments'], 'checked'),
'lang' => $this->lang->t('system', 'allow_comments')
];
}
$this->view->assign('options', $options);
}
// Linkziel
$lang_target = [$this->lang->t('system', 'window_self'), $this->lang->t('system', 'window_blank')];
$this->view->assign('target', $this->get('core.helpers.forms')->selectGenerator('target', [1, 2], $lang_target, $news['target']));
$this->view->assign('target', $this->get('core.helpers.forms')->linkTargetSelectGenerator('target', $news['target']));
$this->view->assign('SEO_FORM_FIELDS', $this->seo->formFields(sprintf(News\Helpers::URL_KEY_PATTERN, $id)));
$this->view->assign('form', array_merge($news, $this->request->getPost()->getAll()));
$this->formTokenHelper->generateFormToken();
......@@ -265,7 +218,7 @@ class Index extends Core\Modules\AdminController
*/
protected function _createPost(array $formData, array $settings)
{
$this->actionHelper->handleCreatePostAction(function() use ($formData, $settings) {
$this->actionHelper->handleCreatePostAction(function () use ($formData, $settings) {
$this->newsValidator->validate($formData);
$insertValues = [
......@@ -306,7 +259,7 @@ class Index extends Core\Modules\AdminController
*/
protected function _editPost(array $formData, array $settings, $id)
{
$this->actionHelper->handleEditPostAction(function() use ($formData, $settings, $id) {
$this->actionHelper->handleEditPostAction(function () use ($formData, $settings, $id) {
$this->newsValidator->validate(
$formData,
sprintf(News\Helpers::URL_KEY_PATTERN, $id)
......@@ -401,4 +354,34 @@ class Index extends Core\Modules\AdminController
{
return $settings['comments'] == 1 && isset($formData['comments']) ? 1 : 0;
}
/**
* @param array $settings
* @param int $readmoreValue
* @param int $commentsValue
*
* @return array
*/
protected function fetchNewsOptions(array $settings, $readmoreValue, $commentsValue)
{
$options = [];
if ($settings['readmore'] == 1 || ($settings['comments'] == 1 && $this->modules->isActive('comments') === true)) {
if ($settings['readmore'] == 1) {
$options[] = [
'name' => 'readmore',
'checked' => $this->get('core.helpers.forms')->selectEntry('readmore', '1', $readmoreValue, 'checked'),
'lang' => $this->lang->t('news', 'activate_readmore')
];
}
if ($settings['comments'] == 1 && $this->modules->isActive('comments') === true) {
$options[] = [
'name' => 'comments',
'checked' => $this->get('core.helpers.forms')->selectEntry('comments', '1', $commentsValue, 'checked'),
'lang' => $this->lang->t('system', 'allow_comments')
];
}
}
return $options;
}
}
......@@ -34,7 +34,7 @@
<div class="col-sm-10">{$categories}</div>
</div>
{if isset($options)}
{if !empty($options)}
<div class="form-group">
<label for="{$options.0.name}" class="col-sm-2 control-label">{lang t="system|options"}</label>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment