Skip to content

Commit f4e2dab

Browse files
committed
Added settings page with information about module
1 parent 8793a5a commit f4e2dab

File tree

7 files changed

+203
-4
lines changed

7 files changed

+203
-4
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,22 @@ that is included in Drupal core.
1414
Module provides preconfigured REST sources and Views for fetching lists nodes
1515
and terms in JSON-format
1616
* /node/[node id]?_format=json - particular node
17-
* /rest/os2web/list/term - list of taxonomy terms
1817
* /rest/os2web/list/node/[taxonomy term id] - list of nodes filtered by
1918
[taxonomy term id]
19+
* /rest/os2web/list/term - list of all taxonomy terms
20+
* /rest/os2web/list/term/[vocabulary machine name] - list of taxonomy terms by vocabulary machine name
2021

22+
For advanced filtering you can use multiple arguments. For example:
23+
```
24+
/rest/os2web/list/node/1+2+3
25+
```
26+
for `AND` condition
27+
```
28+
/rest/os2web/list/node/1,2,3
29+
```
30+
for `OR` condition
31+
32+
**NOTE**: It's not possible to use `AND` condition on filtering taxonomy terms.
2133

2234
## Install
2335
Module is available to download via composer.

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"description": "OS2Web Rest API",
44
"type": "drupal-module",
55
"require": {
6-
"drupal/core": "*",
7-
"drupal/restui": "*"
6+
"drupal/core": "*"
87
},
98
"license": "EUPL-1.2",
109
"minimum-stability": "dev"

os2web_rest_api.info.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ description: 'Provides REST API for OS2Web content'
44
core: 8.x
55
package: 'OS2Web'
66
dependencies:
7-
- restui
7+
- rest
8+
- node
9+
- serialization
10+
- taxonomy
11+
- views
12+
- user

os2web_rest_api.links.menu.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
os2web_rest_api.os2web_reset_api_settings_form:
2+
title: 'OS2Web Rest API'
3+
route_name: os2web_rest_api.os2web_reset_api_settings_form
4+
description: 'Settings form and description on OS2Web Rest API'
5+
parent: system.admin_config_system
6+
weight: 99

os2web_rest_api.module

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ function os2web_rest_api_help($route_name, RouteMatchInterface $route_match) {
1717
$output = '';
1818
$output .= '<h3>' . t('About') . '</h3>';
1919
$output .= '<p>' . t('Provides REST API for OS2Web content') . '</p>';
20+
$output .= '<p>' . t('See module information and settings on <a href="/admin/config/system/os2web-rest-api">configuration page</a>') . '</p>';
2021
return $output;
2122

2223
default:

os2web_rest_api.routing.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
os2web_rest_api.os2web_reset_api_settings_form:
2+
path: '/admin/config/system/os2web-rest-api'
3+
defaults:
4+
_form: '\Drupal\os2web_rest_api\Form\SettingsForm'
5+
_title_callback: '\Drupal\os2web_rest_api\Form\SettingsForm::getTitle'
6+
requirements:
7+
_permission: 'access administration pages'
8+
options:
9+
_admin_route: TRUE

src/Form/SettingsForm.php

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
3+
namespace Drupal\os2web_rest_api\Form;
4+
5+
use Drupal\Core\Config\ConfigFactoryInterface;
6+
use Drupal\Core\Extension\ModuleHandlerInterface;
7+
use Drupal\Core\Form\ConfigFormBase;
8+
use Drupal\Core\Form\FormStateInterface;
9+
use Drupal\Core\Link;
10+
use Drupal\Core\Url;
11+
use Drupal\Core\Render\Markup;
12+
use Symfony\Component\DependencyInjection\ContainerInterface;
13+
14+
/**
15+
* Class SettingsForm.
16+
*/
17+
class SettingsForm extends ConfigFormBase {
18+
19+
/**
20+
* The module handler service.
21+
*
22+
* @var \Drupal\Core\Extension\ModuleHandlerInterface
23+
*/
24+
protected $moduleHandler;
25+
26+
/**
27+
* Constructs a \Drupal\system\ConfigFormBase object.
28+
*
29+
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
30+
* The factory for configuration objects.
31+
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
32+
* The module handler.
33+
*/
34+
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
35+
parent::__construct($config_factory);
36+
$this->moduleHandler = $module_handler;
37+
}
38+
39+
/**
40+
* {@inheritdoc}
41+
*/
42+
public static function create(ContainerInterface $container) {
43+
return new static(
44+
$container->get('config.factory'),
45+
$container->get('module_handler')
46+
);
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
protected function getEditableConfigNames() {
53+
return [
54+
'os2web_rest_api.settings',
55+
];
56+
}
57+
58+
/**
59+
* {@inheritdoc}
60+
*/
61+
public function getFormId() {
62+
return 'os2web_reset_api_settings_form';
63+
}
64+
65+
/**
66+
* Title callback.
67+
*/
68+
public static function getTitle() {
69+
return t('OS2Web Rest API Settings');
70+
}
71+
72+
/**
73+
* {@inheritdoc}
74+
*/
75+
public function buildForm(array $form, FormStateInterface $form_state) {
76+
$form['documentation_header'] = [
77+
'#prefix' => '<h3>',
78+
'#markup' => $this->t('Documentation'),
79+
'#suffix' => '</h3>',
80+
];
81+
82+
$form['documentation']= [
83+
'#prefix' => '<p>',
84+
'#markup' => $this->t('See original documentation for this module and <a href="https://github.com/os2web/os2web_rest_api#how-does-it-work" target="_blank">how does it work</a>.'),
85+
'#suffix' => '</p>',
86+
];
87+
88+
89+
$path_array = [
90+
'OS2WEB Rest list node' => '/admin/structure/views/view/os2web_rest_list_node',
91+
'OS2WEB Rest list term' => '/admin/structure/views/view/os2web_rest_list_term',
92+
];
93+
$predefined_url = [
94+
'#theme' => 'item_list',
95+
'#items' => [],
96+
];
97+
98+
foreach ($path_array as $label => $path) {
99+
$predefined_url['#items'][$label] = Link::fromTextAndUrl($label, Url::fromUri('internal:' . $path, ['absolute' => TRUE]))->toString();
100+
}
101+
$form['urls']= [
102+
'#prefix' => '<p>',
103+
'#markup' => $this->t('Predefined views to export list of entities:@list', [
104+
'@list' => Markup::create(\Drupal::service('renderer')->renderPlain($predefined_url)),
105+
]),
106+
'#suffix' => '</p>',
107+
];
108+
109+
$form['auth_header'] = [
110+
'#prefix' => '<h3>',
111+
'#markup' => $this->t('Authorization'),
112+
'#suffix' => '</h3>',
113+
];
114+
115+
if ($this->moduleHandler->moduleExists('basic_auth')) {
116+
$form['basic_auth'] = [
117+
'#prefix' => '<p>',
118+
'#markup' => $this->t('You can configure basic authorization for listing by editing access section in views @node_list_api_url or @term_list_api_url.', [
119+
'@node_list_api_url' => $predefined_url['#items']['OS2WEB Rest list node'],
120+
'@term_list_api_url' => $predefined_url['#items']['OS2WEB Rest list term'],
121+
]),
122+
'#suffix' => '</p>',
123+
];
124+
}
125+
else {
126+
$form['basic_auth'] = [
127+
'#prefix' => '<p>',
128+
'#markup' => $this->t('To configure basic authorization download and activate <a href="https://www.drupal.org/project/basic_auth" target="_blank">basic_auth</a> module.'),
129+
'#suffix' => '</p>',
130+
];
131+
}
132+
133+
134+
$form['extensions_header'] = [
135+
'#prefix' => '<h3>',
136+
'#markup' => $this->t('Useful extensions'),
137+
'#suffix' => '</h3>',
138+
];
139+
140+
if ($this->moduleHandler->moduleExists('restui')) {
141+
$form['restui'] = [
142+
'#prefix' => '<p>',
143+
'#markup' => $this->t('Get <a href="/admin/config/services/rest">overview on RESTfull API configuration</a>'),
144+
'#suffix' => '</p>',
145+
];
146+
}
147+
else {
148+
$form['restui'] = [
149+
'#prefix' => '<p>',
150+
'#markup' => $this->t('To get overview on RESTfull API configuration you need to download and activate <a href="https://www.drupal.org/project/restui" target="_blank">restui</a> module.'),
151+
'#suffix' => '</p>',
152+
];
153+
}
154+
// There is nothing to save.
155+
// Skipping parent::buildForm($form, $form_state) call.
156+
return $form;
157+
}
158+
159+
/**
160+
* {@inheritdoc}
161+
*/
162+
public function submitForm(array &$form, FormStateInterface $form_state) {
163+
// There is nothing to save here at the current moment.
164+
parent::submitForm($form, $form_state);
165+
}
166+
167+
}

0 commit comments

Comments
 (0)