Skip to content

Commit

Permalink
Convert user plugins to service provider (#40180)
Browse files Browse the repository at this point in the history
* Convert user plugins to service provider

* form path

* Update plugins/user/contactcreator/services/provider.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/joomla/services/provider.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/profile/services/provider.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/terms/services/provider.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/token/services/provider.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/joomla/src/Extension/Joomla.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* Update plugins/user/joomla/src/Extension/Joomla.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* revert debug

* private

* Fix account notification email language (#28)

* Update plugins/user/joomla/src/Extension/Joomla.php

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>

* minor change

---------

Co-authored-by: heelc29 <66922325+heelc29@users.noreply.github.com>
Co-authored-by: Tuan Pham Ngoc <github@joomdonation.com>
  • Loading branch information
3 people authored Mar 29, 2023
1 parent aecd8e4 commit 951e55d
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 182 deletions.
4 changes: 3 additions & 1 deletion plugins/user/contactcreator/contactcreator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_CONTACTCREATOR_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\User\ContactCreator</namespace>
<files>
<filename plugin="contactcreator">contactcreator.php</filename>
<folder plugin="contactcreator">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_user_contactcreator.ini</language>
Expand Down
47 changes: 47 additions & 0 deletions plugins/user/contactcreator/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage User.contactcreator
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\User\ContactCreator\Extension\ContactCreator;

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): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new ContactCreator(
$dispatcher,
(array) PluginHelper::getPlugin('user', 'contactcreator')
);
$plugin->setApplication(Factory::getApplication());

return $plugin;
}
);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
*
* @copyright (C) 2010 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/

use Joomla\CMS\Language\Text;
namespace Joomla\Plugin\User\ContactCreator\Extension;

use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\Component\Contact\Administrator\Table\ContactTable;
use Joomla\String\StringHelper;
Expand All @@ -26,7 +25,7 @@
*
* @since 1.6
*/
class PlgUserContactCreator extends CMSPlugin
final class ContactCreator extends CMSPlugin
{
/**
* Load the language file on instantiation.
Expand All @@ -36,22 +35,6 @@ class PlgUserContactCreator extends CMSPlugin
*/
protected $autoloadLanguage = true;

/**
* Application Instance
*
* @var \Joomla\CMS\Application\CMSApplication
* @since 4.0.0
*/
protected $app;

/**
* Database Driver Instance
*
* @var \Joomla\Database\DatabaseDriver
* @since 4.0.0
*/
protected $db;

/**
* Utility method to act on a user after it has been saved.
*
Expand Down Expand Up @@ -89,7 +72,7 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
$categoryId = $this->params->get('category', 0);

if (empty($categoryId)) {
$this->app->enqueueMessage(Text::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'), 'error');
$this->getApplication()->enqueueMessage($this->getApplication()->getLanguage()->_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'), 'error');

return;
}
Expand All @@ -107,7 +90,7 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
$contact->user_id = $user_id;
$contact->email_to = $user['email'];
$contact->catid = $categoryId;
$contact->access = (int) $this->app->get('access');
$contact->access = (int) $this->getApplication()->get('access');
$contact->language = '*';
$contact->generateAlias();

Expand Down Expand Up @@ -137,7 +120,7 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
}
}

$this->app->enqueueMessage(Text::_('PLG_CONTACTCREATOR_ERR_FAILED_CREATING_CONTACT'), 'error');
$this->getApplication()->enqueueMessage($this->getApplication()->getLanguage()->_('PLG_CONTACTCREATOR_ERR_FAILED_CREATING_CONTACT'), 'error');
}

/**
Expand All @@ -151,7 +134,7 @@ public function onUserAfterSave($user, $isnew, $success, $msg): void
*
* @since 3.2.3
*/
protected function generateAliasAndName($alias, $name, $categoryId)
private function generateAliasAndName($alias, $name, $categoryId)
{
$table = $this->getContactTable();

Expand All @@ -173,8 +156,8 @@ protected function generateAliasAndName($alias, $name, $categoryId)
*
* @since 3.2.3
*/
protected function getContactTable()
private function getContactTable()
{
return $this->app->bootComponent('com_contact')->getMVCFactory()->createTable('Contact', 'Administrator', ['dbo' => $this->db]);
return $this->getApplication()->bootComponent('com_contact')->getMVCFactory()->createTable('Contact', 'Administrator');
}
}
4 changes: 3 additions & 1 deletion plugins/user/joomla/joomla.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.0.0</version>
<description>PLG_USER_JOOMLA_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\User\Joomla</namespace>
<files>
<filename plugin="joomla">joomla.php</filename>
<folder plugin="joomla">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_user_joomla.ini</language>
Expand Down
49 changes: 49 additions & 0 deletions plugins/user/joomla/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage User.joomla
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\User\Joomla\Extension\Joomla;

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): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Joomla(
$dispatcher,
(array) PluginHelper::getPlugin('user', 'joomla')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Loading

0 comments on commit 951e55d

Please sign in to comment.