first commit
This commit is contained in:
21
plugins/webservices/contact/contact.xml
Normal file
21
plugins/webservices/contact/contact.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="webservices" method="upgrade">
|
||||
<name>plg_webservices_contact</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2019-09</creationDate>
|
||||
<copyright>(C) 2019 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_WEBSERVICES_CONTACT_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\WebServices\Contact</namespace>
|
||||
<files>
|
||||
<folder plugin="contact">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_webservices_contact.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_webservices_contact.sys.ini</language>
|
||||
</languages>
|
||||
</extension>
|
||||
46
plugins/webservices/contact/services/provider.php
Normal file
46
plugins/webservices/contact/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Webservices.contact
|
||||
*
|
||||
* @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\WebServices\Contact\Extension\Contact;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function register(Container $container): void
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Contact(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('webservices', 'contact')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
140
plugins/webservices/contact/src/Extension/Contact.php
Normal file
140
plugins/webservices/contact/src/Extension/Contact.php
Normal file
@ -0,0 +1,140 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Webservices.contact
|
||||
*
|
||||
* @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\Plugin\WebServices\Contact\Extension;
|
||||
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Router\ApiRouter;
|
||||
use Joomla\Router\Route;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Web Services adapter for com_contact.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class Contact extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Registers com_contact's API's routes in the application
|
||||
*
|
||||
* @param ApiRouter &$router The API Routing object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onBeforeApiRoute(&$router)
|
||||
{
|
||||
$route = new Route(
|
||||
['POST'],
|
||||
'v1/contacts/form/:id',
|
||||
'contact.submitForm',
|
||||
['id' => '(\d+)'],
|
||||
['component' => 'com_contact']
|
||||
);
|
||||
|
||||
$router->addRoute($route);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/contacts',
|
||||
'contact',
|
||||
['component' => 'com_contact']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/contacts/categories',
|
||||
'categories',
|
||||
['component' => 'com_categories', 'extension' => 'com_contact']
|
||||
);
|
||||
|
||||
$this->createFieldsRoutes($router);
|
||||
|
||||
$this->createContentHistoryRoutes($router);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fields routes
|
||||
*
|
||||
* @param ApiRouter &$router The API Routing object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function createFieldsRoutes(&$router)
|
||||
{
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/contacts/contact',
|
||||
'fields',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.contact']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/contacts/mail',
|
||||
'fields',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.mail']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/contacts/categories',
|
||||
'fields',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.categories']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/groups/contacts/contact',
|
||||
'groups',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.contact']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/groups/contacts/mail',
|
||||
'groups',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.mail']
|
||||
);
|
||||
|
||||
$router->createCRUDRoutes(
|
||||
'v1/fields/groups/contacts/categories',
|
||||
'groups',
|
||||
['component' => 'com_fields', 'context' => 'com_contact.categories']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contenthistory routes
|
||||
*
|
||||
* @param ApiRouter &$router The API Routing object
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
private function createContentHistoryRoutes(&$router)
|
||||
{
|
||||
$defaults = [
|
||||
'component' => 'com_contenthistory',
|
||||
'type_alias' => 'com_contact.contact',
|
||||
'type_id' => 2,
|
||||
];
|
||||
$getDefaults = array_merge(['public' => false], $defaults);
|
||||
|
||||
$routes = [
|
||||
new Route(['GET'], 'v1/contacts/:id/contenthistory', 'history.displayList', ['id' => '(\d+)'], $getDefaults),
|
||||
new Route(['PATCH'], 'v1/contacts/:id/contenthistory/keep', 'history.keep', ['id' => '(\d+)'], $defaults),
|
||||
new Route(['DELETE'], 'v1/contacts/:id/contenthistory', 'history.delete', ['id' => '(\d+)'], $defaults),
|
||||
];
|
||||
|
||||
$router->addRoutes($routes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user