diff --git a/src/administrator/components/com_weblinks/weblinks.xml b/src/administrator/components/com_weblinks/weblinks.xml index a872b1cc3e6..7674c7cf816 100644 --- a/src/administrator/components/com_weblinks/weblinks.xml +++ b/src/administrator/components/com_weblinks/weblinks.xml @@ -63,5 +63,10 @@ ##BACKEND_LANGUAGE_FILES## + + + ##API_COMPONENT_FILES## + + diff --git a/src/administrator/manifests/packages/pkg_weblinks.xml b/src/administrator/manifests/packages/pkg_weblinks.xml index 35dc0531bc4..03965f0db5f 100644 --- a/src/administrator/manifests/packages/pkg_weblinks.xml +++ b/src/administrator/manifests/packages/pkg_weblinks.xml @@ -22,6 +22,7 @@ plg_search_weblinks.zip plg_system_weblinks.zip plg_editors-xtd_weblink.zip + plg_webservices_weblinks.zip en-GB/en-GB.pkg_weblinks.sys.ini diff --git a/src/api/components/com_weblinks/Controller/WeblinksController.php b/src/api/components/com_weblinks/Controller/WeblinksController.php new file mode 100644 index 00000000000..ee895cb3922 --- /dev/null +++ b/src/api/components/com_weblinks/Controller/WeblinksController.php @@ -0,0 +1,77 @@ +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); + } +} diff --git a/src/api/components/com_weblinks/View/Weblinks/JsonApiView.php b/src/api/components/com_weblinks/View/Weblinks/JsonApiView.php new file mode 100644 index 00000000000..304e7fc97f8 --- /dev/null +++ b/src/api/components/com_weblinks/View/Weblinks/JsonApiView.php @@ -0,0 +1,147 @@ +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); + } +} diff --git a/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.ini b/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.ini new file mode 100644 index 00000000000..e1b9bf6b752 --- /dev/null +++ b/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.ini @@ -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." diff --git a/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.sys.ini b/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.sys.ini new file mode 100644 index 00000000000..e1b9bf6b752 --- /dev/null +++ b/src/plugins/webservices/weblinks/en-GB/en-GB.plg_webservices_weblinks.sys.ini @@ -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." diff --git a/src/plugins/webservices/weblinks/weblinks.php b/src/plugins/webservices/weblinks/weblinks.php new file mode 100644 index 00000000000..a2fd61a4546 --- /dev/null +++ b/src/plugins/webservices/weblinks/weblinks.php @@ -0,0 +1,75 @@ +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'] + ); + } +} diff --git a/src/plugins/webservices/weblinks/weblinks.xml b/src/plugins/webservices/weblinks/weblinks.xml new file mode 100644 index 00000000000..8d0fecd4b09 --- /dev/null +++ b/src/plugins/webservices/weblinks/weblinks.xml @@ -0,0 +1,18 @@ + + + plg_webservices_weblinks + Joomla! Project + August 2017 + (C) 2005 - 2019 Open Source Matters. All rights reserved. + GNU General Public License version 2 or later; see LICENSE.txt + admin@joomla.org + www.joomla.org + 4.0.0 + PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION + + ##FILES## + + + ##LANGUAGE_FILES## + +