-
Notifications
You must be signed in to change notification settings - Fork 89
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
Webservices #407
Open
o-samoilov
wants to merge
4
commits into
joomla-extensions:4.0-dev
Choose a base branch
from
o-samoilov:webservices
base: 4.0-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Webservices #407
Changes from 2 commits
Commits
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 contains 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 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
78 changes: 78 additions & 0 deletions
78
src/api/components/com_weblinks/Controller/WeblinksController.php
This file contains 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,78 @@ | ||
<?php | ||
/** | ||
* @package Joomla.API | ||
* @subpackage com_weblinks | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\Component\Weblinks\Api\Controller; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\Access\Exception\NotAllowed; | ||
use Joomla\CMS\Application\CMSApplication; | ||
use Joomla\CMS\Form\Form; | ||
use Joomla\CMS\MVC\Controller\ApiController; | ||
use Joomla\CMS\MVC\Factory\LegacyFactory; | ||
use Joomla\CMS\MVC\Factory\MVCFactoryInterface; | ||
use Joomla\CMS\MVC\View\JsonApiView; | ||
use Joomla\CMS\MVC\Controller\Exception\ResourceNotFound; | ||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; | ||
use Joomla\Input\Input; | ||
use Joomla\String\Inflector; | ||
use Tobscure\JsonApi\Exception\InvalidParameterException; | ||
|
||
/** | ||
* The weblinks controller | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
class WeblinksController extends ApiController | ||
{ | ||
/** | ||
* The content type of the item. | ||
* | ||
* @var string | ||
* @since 4.0.0 | ||
*/ | ||
protected $contentType = 'weblinks'; | ||
|
||
/** | ||
* The default view for the display method. | ||
* | ||
* @var string | ||
* @since 3.0 | ||
*/ | ||
protected $default_view = 'weblinks'; | ||
|
||
/** | ||
* Method to save a record. | ||
* | ||
* @param integer $recordKey The primary key of the item (if exists) | ||
* | ||
* @return integer The record ID on success, false on failure | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
protected function save($recordKey = null) | ||
{ | ||
$data = (array) json_decode($this->input->json->getRaw(), true); | ||
|
||
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) | ||
{ | ||
if (isset($data[$field->name])) | ||
{ | ||
!isset($data['com_fields']) && $data['com_fields'] = []; | ||
|
||
$data['com_fields'][$field->name] = $data[$field->name]; | ||
unset($data[$field->name]); | ||
} | ||
} | ||
|
||
$this->input->set('data', $data); | ||
|
||
return parent::save($recordKey); | ||
} | ||
} |
147 changes: 147 additions & 0 deletions
147
src/api/components/com_weblinks/View/Weblinks/JsonapiView.php
This file contains 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,147 @@ | ||
<?php | ||
/** | ||
* @package Joomla.API | ||
* @subpackage com_redirect | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
namespace Joomla\Component\Weblinks\Api\View\Weblinks; | ||
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView; | ||
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper; | ||
|
||
/** | ||
* The weblinks view | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
class JsonapiView extends BaseApiView | ||
{ | ||
/** | ||
* The fields to render item in the documents | ||
* | ||
* @var array | ||
* @since 4.0.0 | ||
*/ | ||
protected $fieldsToRenderItem = [ | ||
'id', | ||
'catid', | ||
'title', | ||
'alias', | ||
'url', | ||
'description', | ||
'hits', | ||
'state', | ||
'checked_out', | ||
'checked_out_time', | ||
'ordering', | ||
'access', | ||
'params', | ||
'language', | ||
'created', | ||
'created_by', | ||
'created_by_alias', | ||
'modified', | ||
'modified_by', | ||
'metakey', | ||
'metadesc', | ||
'metadata', | ||
'featured', | ||
'xreference', | ||
'publish_up', | ||
'publish_down', | ||
'version', | ||
'images', | ||
'tags' | ||
]; | ||
|
||
/** | ||
* The fields to render items in the documents | ||
* | ||
* @var array | ||
* @since 4.0.0 | ||
*/ | ||
protected $fieldsToRenderList = [ | ||
'id', | ||
'title', | ||
'alias', | ||
'checked_out', | ||
'checked_out_time', | ||
'catid', | ||
'created', | ||
'created_by', | ||
'hits', | ||
'state', | ||
'access', | ||
'ordering', | ||
'language', | ||
'publish_up', | ||
'publish_down', | ||
'language_title', | ||
'language_image', | ||
'editor', | ||
'access_level', | ||
'category_title' | ||
]; | ||
|
||
/** | ||
* Execute and display a template script. | ||
* | ||
* @param array|null $items Array of items | ||
* | ||
* @return string | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public function displayList(array $items = null) | ||
{ | ||
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) | ||
{ | ||
$this->fieldsToRenderList[] = $field->name; | ||
} | ||
|
||
return parent::displayList(); | ||
} | ||
|
||
/** | ||
* Execute and display a template script. | ||
* | ||
* @param object $item Item | ||
* | ||
* @return string | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public function displayItem($item = null) | ||
{ | ||
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) | ||
{ | ||
$this->fieldsToRenderItem[] = $field->name; | ||
} | ||
|
||
return parent::displayItem(); | ||
} | ||
|
||
/** | ||
* Prepare item before render. | ||
* | ||
* @param object $item The model item | ||
* | ||
* @return object | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
protected function prepareItem($item) | ||
{ | ||
foreach (FieldsHelper::getFields('com_weblinks.weblink', $item, true) as $field) | ||
{ | ||
$item->{$field->name} = isset($field->apivalue) ? $field->apivalue : $field->rawvalue; | ||
} | ||
|
||
return parent::prepareItem($item); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.sys
This file contains 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,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_WEBSERVICES_WEBLINKS="Web Services - Weblinks" | ||
PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION="Used to add weblinks routes to the API for your website." |
7 changes: 7 additions & 0 deletions
7
src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.sys.ini
This file contains 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,7 @@ | ||
; Joomla! Project | ||
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved. | ||
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php | ||
; Note : All ini files need to be saved as UTF-8 | ||
|
||
PLG_WEBSERVICES_WEBLINKS="Web Services - Weblinks" | ||
PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION="Used to add weblinks routes to the API for your website." |
This file contains 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,75 @@ | ||
<?php | ||
/** | ||
* @package Joomla.Plugin | ||
* @subpackage Webservices.Weblinks | ||
* | ||
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved. | ||
* @license GNU General Public License version 2 or later; see LICENSE.txt | ||
*/ | ||
|
||
defined('_JEXEC') or die; | ||
|
||
use Joomla\CMS\Plugin\CMSPlugin; | ||
use Joomla\CMS\Router\ApiRouter; | ||
|
||
/** | ||
* Web Services adapter for com_weblinks. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
class PlgWebservicesWeblinks extends CMSPlugin | ||
{ | ||
/** | ||
* Load the language file on instantiation. | ||
* | ||
* @var boolean | ||
* @since 4.0.0 | ||
*/ | ||
protected $autoloadLanguage = true; | ||
|
||
/** | ||
* Registers com_weblinks's API's routes in the application | ||
* | ||
* @param ApiRouter &$router The API Routing object | ||
* | ||
* @return void | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public function onBeforeApiRoute(&$router) | ||
{ | ||
$router->createCRUDRoutes('v1/weblinks', 'weblinks', ['component' => 'com_weblinks']); | ||
|
||
$router->createCRUDRoutes( | ||
'v1/weblinks/categories', | ||
'categories', | ||
['component' => 'com_categories', 'extension' => 'com_weblinks'] | ||
); | ||
|
||
$this->createFieldsRoutes($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/weblinks', | ||
'fields', | ||
['component' => 'com_fields', 'context' => 'com_weblinks.weblink'] | ||
); | ||
|
||
$router->createCRUDRoutes( | ||
'v1/fields/groups/weblinks', | ||
'groups', | ||
['component' => 'com_fields', 'context' => 'com_weblinks.weblink'] | ||
); | ||
} | ||
} |
This file contains 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,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<extension version="3.1" type="plugin" group="webservices" method="upgrade"> | ||
<name>plg_webservices_weblinks</name> | ||
<author>Joomla! Project</author> | ||
<creationDate>August 2017</creationDate> | ||
<copyright>(C) 2005 - 2019 Open Source Matters. All rights reserved.</copyright> | ||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license> | ||
<authorEmail>[email protected]</authorEmail> | ||
<authorUrl>www.joomla.org</authorUrl> | ||
<version>4.0.0</version> | ||
<description>PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION</description> | ||
<files> | ||
##FILES## | ||
</files> | ||
<languages folder="administrator/language"> | ||
##LANGUAGE_FILES## | ||
</languages> | ||
</extension> |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the file name should be
src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.ini
not.sys
at the end ;)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, thanks :)