Commit fd891efe authored by Tino Goratsch's avatar Tino Goratsch

decoupled the menu item management from the articles module some more

parent d1bb7fda
......@@ -7,13 +7,14 @@
namespace ACP3\Modules\ACP3\Articles\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Core\Controller\AbstractFrontendAction;
use ACP3\Modules\ACP3\Articles;
/**
* Class Create
* @package ACP3\Modules\ACP3\Articles\Controller\Admin\Index
*/
class Create extends AbstractFormAction
class Create extends AbstractFrontendAction
{
/**
* @var \ACP3\Modules\ACP3\Articles\Validation\AdminFormValidation
......@@ -27,6 +28,10 @@ class Create extends AbstractFormAction
* @var Articles\Model\ArticlesModel
*/
protected $articlesModel;
/**
* @var Core\Helpers\Forms
*/
protected $formsHelper;
/**
* @param \ACP3\Core\Controller\Context\FrontendContext $context
......@@ -42,11 +47,12 @@ class Create extends AbstractFormAction
Articles\Validation\AdminFormValidation $adminFormValidation,
Core\Helpers\FormToken $formTokenHelper
) {
parent::__construct($context, $formsHelper);
parent::__construct($context);
$this->articlesModel = $articlesModel;
$this->adminFormValidation = $adminFormValidation;
$this->formTokenHelper = $formTokenHelper;
$this->formsHelper = $formsHelper;
}
/**
......@@ -80,11 +86,8 @@ class Create extends AbstractFormAction
$this->adminFormValidation->validate($formData);
$formData['user_id'] = $this->user->getUserId();
$articleId = $this->articlesModel->save($formData);
$this->createOrUpdateMenuItem($formData, $articleId);
return $articleId;
return $this->articlesModel->save($formData);
});
}
}
......@@ -7,13 +7,14 @@
namespace ACP3\Modules\ACP3\Articles\Controller\Admin\Index;
use ACP3\Core;
use ACP3\Core\Controller\AbstractFrontendAction;
use ACP3\Modules\ACP3\Articles;
/**
* Class Edit
* @package ACP3\Modules\ACP3\Articles\Controller\Admin\Index
*/
class Edit extends AbstractFormAction
class Edit extends AbstractFrontendAction
{
/**
* @var \ACP3\Modules\ACP3\Articles\Validation\AdminFormValidation
......@@ -27,6 +28,10 @@ class Edit extends AbstractFormAction
* @var Articles\Model\ArticlesModel
*/
protected $articlesModel;
/**
* @var Core\Helpers\Forms
*/
protected $formsHelper;
/**
* @param \ACP3\Core\Controller\Context\FrontendContext $context
......@@ -42,11 +47,12 @@ class Edit extends AbstractFormAction
Articles\Validation\AdminFormValidation $adminFormValidation,
Core\Helpers\FormToken $formTokenHelper
) {
parent::__construct($context, $formsHelper);
parent::__construct($context);
$this->adminFormValidation = $adminFormValidation;
$this->formTokenHelper = $formTokenHelper;
$this->articlesModel = $articlesModel;
$this->formsHelper = $formsHelper;
}
/**
......@@ -88,11 +94,8 @@ class Edit extends AbstractFormAction
->validate($formData);
$formData['user_id'] = $this->user->getUserId();
$result = $this->articlesModel->save($formData, $id);
$this->createOrUpdateMenuItem($formData, $id);
return $result;
return $this->articlesModel->save($formData, $id);
});
}
}
......@@ -16,7 +16,7 @@
<div id="tab-2" class="tab-pane fade">
{include file="asset:System/Partials/form_group.input_text.tpl" name="title" value=$form.title required=true maxlength=120 data_attributes=['seo-slug-base' => 'true'] label={lang t="articles|title"}}
{include file="asset:System/Partials/form_group.wysiwyg.tpl" name="text" value=$form.text required=true advanced=true label={lang t="articles|text"}}
{event name="menus.layout.render_manage_menu_item" path=$SEO_ROUTE_NAME}
{event name="menus.layout.render_manage_menu_item" uri_pattern=$SEO_URI_PATTERN path=$SEO_ROUTE_NAME}
</div>
{event name="seo.layout.render_form_fields" uri_pattern=$SEO_URI_PATTERN path=$SEO_ROUTE_NAME}
</div>
......
......@@ -7,8 +7,6 @@ services:
- '@articles.model'
- '@articles.validation.admin_form_validation'
- '@core.helpers.formToken'
calls:
- ['setManageMenuItemHelper', ['@?menus.helpers.managemenuitem']]
articles.controller.admin.index.delete:
class: ACP3\Modules\ACP3\Articles\Controller\Admin\Index\Delete
......@@ -30,8 +28,6 @@ services:
- '@articles.model'
- '@articles.validation.admin_form_validation'
- '@core.helpers.formToken'
calls:
- ['setManageMenuItemHelper', ['@?menus.helpers.managemenuitem']]
articles.controller.admin.index.index:
class: ACP3\Modules\ACP3\Articles\Controller\Admin\Index\Index
......
......@@ -4,62 +4,41 @@
* See the LICENCE file at the top-level module directory for licencing details.
*/
namespace ACP3\Modules\ACP3\Articles\Controller\Admin\Index;
namespace ACP3\Modules\ACP3\Menus\Event\Listener;
use ACP3\Core;
use ACP3\Core\Controller\AbstractFrontendAction;
use ACP3\Modules\ACP3\Articles;
use ACP3\Modules\ACP3\Menus;
/**
* Class AbstractFormAction
* @package ACP3\Modules\ACP3\Articles\Controller\Admin\Index
*/
abstract class AbstractFormAction extends AbstractFrontendAction
use ACP3\Core\ACL;
use ACP3\Core\Model\Event\ModelSaveEvent;
use ACP3\Modules\ACP3\Menus\Helpers\ManageMenuItem;
class ManageMenuItemOnModelSaveAfterListener
{
/**
* @var Core\Helpers\Forms
*/
protected $formsHelper;
/**
* @var \ACP3\Modules\ACP3\Menus\Helpers\ManageMenuItem
* @var ManageMenuItem
*/
protected $manageMenuItemHelper;
private $menuItemManager;
/**
* AbstractFormAction constructor.
* @param Core\Controller\Context\FrontendContext $context
* @param Core\Helpers\Forms $formsHelper
* @var ACL
*/
public function __construct(
Core\Controller\Context\FrontendContext $context,
Core\Helpers\Forms $formsHelper
) {
parent::__construct($context);
$this->formsHelper = $formsHelper;
}
private $acl;
/**
* @param \ACP3\Modules\ACP3\Menus\Helpers\ManageMenuItem $manageMenuItemHelper
*
* @return $this
* OnModelSaveAfterListener constructor.
* @param ACL $acl
* @param ManageMenuItem $menuItemManager
*/
public function setManageMenuItemHelper(Menus\Helpers\ManageMenuItem $manageMenuItemHelper)
public function __construct(ACL $acl, ManageMenuItem $menuItemManager)
{
$this->manageMenuItemHelper = $manageMenuItemHelper;
return $this;
$this->menuItemManager = $menuItemManager;
$this->acl = $acl;
}
/**
* @param array $formData
* @param int $articleId
*/
protected function createOrUpdateMenuItem(array $formData, $articleId)
public function createOrUpdateMenuItem(ModelSaveEvent $event)
{
if ($this->acl->hasPermission('admin/menus/items/create') === true
&& $this->hasNecessaryMenuItemFormFields()) {
&& $this->hasNecessaryMenuItemFormFields( $event->getRawData())) {
$formData = $event->getRawData();
$data = [
'mode' => 4,
'block_id' => $formData['block_id'],
......@@ -69,8 +48,8 @@ abstract class AbstractFormAction extends AbstractFrontendAction
'target' => 1
];
$this->manageMenuItemHelper->manageMenuItem(
sprintf(Articles\Helpers::URL_KEY_PATTERN, $articleId),
$this->menuItemManager->manageMenuItem(
sprintf($formData['menu_item_uri_pattern'], $event->getEntryId()),
isset($formData['create']) === true,
$data
);
......@@ -78,10 +57,17 @@ abstract class AbstractFormAction extends AbstractFrontendAction
}
/**
* @param array $formData
* @return bool
*/
private function hasNecessaryMenuItemFormFields()
private function hasNecessaryMenuItemFormFields(array $formData)
{
return isset($formData['block_id'], $formData['parent_id'], $formData['display'], $formData['menu_item_title']);
return isset(
$formData['block_id'],
$formData['parent_id'],
$formData['display'],
$formData['menu_item_title'],
$formData['menu_item_uri_pattern']
);
}
}
......@@ -84,7 +84,8 @@ class OnMenusLayoutRenderManageMenuItemListener
$this->fetchCreateMenuItemOption(!empty($menuItem) ? 1 : 0)
)
->assign('form', $this->modifyFormValues($menuItem))
->assign($formFields);
->assign($formFields)
->assign('uri_pattern', $parameters['uri_pattern']);
$this->view->displayTemplate('Menus/Partials/manage_menu_item.tpl');
}
......
......@@ -29,6 +29,7 @@
</div>
</div>
{include file="asset:System/Partials/form_group.button_group.tpl" options=$display required=true label={lang t="menus|display_item"}}
<input type="hidden" name="menu_item_uri_pattern" value="{$uri_pattern}">
</div>
{javascripts}
{include_js module="menus" file="manage-menu-item"}
......
......@@ -9,6 +9,14 @@ services:
tags:
- { name: core.eventListener, event: menus.model.menus.before_delete, method: execute }
menus.event.manage_menu_item_on_model_after_save_listener:
class: ACP3\Modules\ACP3\Menus\Event\Listener\ManageMenuItemOnModelSaveAfterListener
arguments:
- '@core.acl'
- '@menus.helpers.managemenuitem'
tags:
- { name: core.eventListener, event: core.model.after_save, method: createOrUpdateMenuItem }
menus.event.update_menus_cache_on_model_after_save_listener:
class: ACP3\Modules\ACP3\Menus\Event\Listener\UpdateMenusCacheOnModelAfterSaveListener
arguments:
......
......@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added the new data grid column renderer `RouteColumnRenderer` which makes it possible specify and open routes in new tabs
### Changed
- Decoupled the menu item management from the articles module some more
### Fixed
- Fixed the bug that it was not possible to create new articles when the menu items module was installed and active, but there were no menus at all
......
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