-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Convert mod_messages to service provider #42735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
082763e
Convert mod_messages to service provider
joomlaweby 9838d22
Merge branch '5.1-dev' of github.com:joomlaweby/joomla-cms into mod-m…
joomlaweby 74342b0
Coding standards in mod_messages
joomlaweby 1edc872
Coding standards for mod_messages
joomlaweby 862d068
Coding standards for mod_messages
joomlaweby e9c00b2
Coding standard
joomlaweby f60d707
Merge branch '5.1-dev' of https://github.com/joomla/joomla-cms into m…
joomlaweby 5b3a8d0
Multiline condition and copyright comments fixed
joomlaweby 0af9b58
Merge branch '5.1-dev' into mod-messages
joomlaweby 24ba818
Merge branch '5.1-dev' into mod-messages
joomlaweby 973533d
Merge branch '5.1-dev' into mod-messages
joomlaweby 769c4ab
Merge branch '5.1-dev' into mod-messages
joomlaweby 37acdac
Merge branch '5.1-dev' into mod-messages
LadySolveig 8e22c97
Merge branch '5.1-dev' into mod-messages
LadySolveig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Administrator | ||
| * @subpackage mod_messages | ||
| * | ||
| * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| use Joomla\CMS\Extension\Service\Provider\HelperFactory; | ||
| use Joomla\CMS\Extension\Service\Provider\Module; | ||
| use Joomla\CMS\Extension\Service\Provider\ModuleDispatcherFactory; | ||
| use Joomla\DI\Container; | ||
| use Joomla\DI\ServiceProviderInterface; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('_JEXEC') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * The messages module service provider. | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| return new class () implements ServiceProviderInterface { | ||
| /** | ||
| * Registers the service provider with a DI container. | ||
| * | ||
| * @param Container $container The DI container. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function register(Container $container) | ||
| { | ||
| $container->registerServiceProvider(new ModuleDispatcherFactory('\\Joomla\\Module\\Messages')); | ||
| $container->registerServiceProvider(new HelperFactory('\\Joomla\\Module\\Messages\\Administrator\\Helper')); | ||
|
|
||
| $container->registerServiceProvider(new Module()); | ||
| } | ||
| }; | ||
63 changes: 63 additions & 0 deletions
63
administrator/modules/mod_messages/src/Dispatcher/Dispatcher.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Administrator | ||
| * @subpackage mod_messages | ||
| * | ||
| * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> | ||
joomlaweby marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Module\Messages\Administrator\Dispatcher; | ||
|
|
||
| use Joomla\CMS\Dispatcher\AbstractModuleDispatcher; | ||
| use Joomla\CMS\Helper\HelperFactoryAwareInterface; | ||
| use Joomla\CMS\Helper\HelperFactoryAwareTrait; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('_JEXEC') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Dispatcher class for mod_messages | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class Dispatcher extends AbstractModuleDispatcher implements HelperFactoryAwareInterface | ||
| { | ||
| use HelperFactoryAwareTrait; | ||
|
|
||
| /** | ||
| * Runs the dispatcher. | ||
| * | ||
| * @return void | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function dispatch() | ||
| { | ||
| // Check permissions. | ||
| if (!$this->getApplication()->getIdentity()->authorise('core.login.admin') | ||
| || !$this->getApplication()->getIdentity()->authorise('core.manage', 'com_messages')) { | ||
richard67 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| parent::dispatch(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the layout data. | ||
| * | ||
| * @return array | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| protected function getLayoutData() | ||
| { | ||
| $data = parent::getLayoutData(); | ||
|
|
||
| $data['countUnread'] = $this->getHelperFactory()->getHelper('MessagesHelper')->getUnreadMessagesCount($data['params'], $this->getApplication()); | ||
|
|
||
| return $data; | ||
| } | ||
| } | ||
58 changes: 58 additions & 0 deletions
58
administrator/modules/mod_messages/src/Helper/MessagesHelper.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * @package Joomla.Administrator | ||
| * @subpackage mod_messages | ||
| * | ||
| * @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org> | ||
| * @license GNU General Public License version 2 or later; see LICENSE.txt | ||
| */ | ||
|
|
||
| namespace Joomla\Module\Messages\Administrator\Helper; | ||
|
|
||
| use Joomla\CMS\Application\AdministratorApplication; | ||
| use Joomla\Registry\Registry; | ||
|
|
||
| // phpcs:disable PSR1.Files.SideEffects | ||
| \defined('_JEXEC') or die; | ||
| // phpcs:enable PSR1.Files.SideEffects | ||
|
|
||
| /** | ||
| * Helper for mod_messages | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| class MessagesHelper | ||
| { | ||
| /** | ||
| * Get count of unread messages. | ||
| * | ||
| * @param Registry $params Object holding the module parameters | ||
| * @param AdministratorApplication $app The application | ||
| * | ||
| * @return integer | ||
| * | ||
| * @since __DEPLOY_VERSION__ | ||
| */ | ||
| public function getUnreadMessagesCount(Registry $params, AdministratorApplication $app) | ||
| { | ||
| // Try to get the items from the messages model | ||
| try { | ||
| /** | ||
| * @var \Joomla\Component\Messages\Administrator\Model\MessagesModel $messagesModel | ||
| * | ||
| */ | ||
| $messagesModel = $app->bootComponent('com_messages')->getMVCFactory() | ||
| ->createModel('Messages', 'Administrator', ['ignore_request' => true]); | ||
| $messagesModel->setState('filter.state', 0); | ||
| $messages = $messagesModel->getItems(); | ||
|
|
||
| return \count($messages); | ||
| } catch (RuntimeException $e) { | ||
joomlaweby marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| $messages = []; | ||
|
|
||
| // Still render the error message from the Exception object | ||
| $app->enqueueMessage($e->getMessage(), 'error'); | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.