From aa7afc7428e2fdb618afbd57a83241e73cc5b49e Mon Sep 17 00:00:00 2001 From: andriyun Date: Mon, 21 Feb 2022 11:30:53 +0100 Subject: [PATCH 1/2] POC REST export POST request --- src/Plugin/views/display/Os2webRestExport.php | 117 ++++++++++++++++++ src/Plugin/views/exposed_form/Os2webBasic.php | 31 +++++ 2 files changed, 148 insertions(+) create mode 100644 src/Plugin/views/display/Os2webRestExport.php create mode 100644 src/Plugin/views/exposed_form/Os2webBasic.php diff --git a/src/Plugin/views/display/Os2webRestExport.php b/src/Plugin/views/display/Os2webRestExport.php new file mode 100644 index 0000000..4327df5 --- /dev/null +++ b/src/Plugin/views/display/Os2webRestExport.php @@ -0,0 +1,117 @@ +view->storage->id(); + $display_id = $this->display['id']; + + if ($route = $collection->get("view.$view_id.$display_id")) { + // OS2Web REST exports should only respond to GET and POST methods. + $route->setMethods(['GET', 'POST']); + } + } + + /** + * {@inheritdoc} + */ + public function displaysExposed() { + return TRUE; + } + + /** + * {@inheritdoc} + */ + public function usesExposed() { + $this->has_exposed = TRUE; + return $this->has_exposed; + } + + /** + * {@inheritdoc} + */ + protected function defineOptions() { + $options = parent::defineOptions(); + // Restore exposed form and blocks. + $options['exposed_form'] = [ + 'contains' => [ + 'type' => ['default' => 'basic'], + 'options' => ['default' => []], + ], + 'merge_defaults' => [$this, 'mergePlugin'], + ]; + $options['exposed_block'] = ['default' => FALSE]; + return $options; + } + + + /** + * {@inheritdoc} + */ + public function optionsSummary(&$categories, &$options) { + parent::optionsSummary($categories, $options); + + $categories['exposed'] = [ + 'title' => $this->t('Exposed form'), + 'column' => 'third', + 'build' => [ + '#weight' => 1, + ], + ]; + if ($this->usesExposedFormInBlock()) { + $options['exposed_block'] = [ + 'category' => 'exposed', + 'title' => $this->t('Exposed form in block'), + 'value' => $this->getOption('exposed_block') ? $this->t('Yes') : $this->t('No'), + 'desc' => $this->t('Allow the exposed form to appear in a block instead of the view.'), + ]; + } + + /** @var \Drupal\views\Plugin\views\exposed_form\ExposedFormPluginInterface $exposed_form_plugin */ + $exposed_form_plugin = $this->getPlugin('exposed_form'); + if (!$exposed_form_plugin) { + // Default to the no cache control plugin. + $exposed_form_plugin = Views::pluginManager('exposed_form')->createInstance('basic'); + } + + $exposed_form_str = $exposed_form_plugin->summaryTitle(); + + $options['exposed_form'] = [ + 'category' => 'exposed', + 'title' => $this->t('Exposed form style'), + 'value' => $exposed_form_plugin->pluginTitle(), + 'setting' => $exposed_form_str, + 'desc' => $this->t('Select the kind of exposed filter to use.'), + ]; + + if ($exposed_form_plugin->usesOptions()) { + $options['exposed_form']['links']['exposed_form_options'] = $this->t('Exposed form settings for this exposed form style.'); + } + + } + +} diff --git a/src/Plugin/views/exposed_form/Os2webBasic.php b/src/Plugin/views/exposed_form/Os2webBasic.php new file mode 100644 index 0000000..e16b98a --- /dev/null +++ b/src/Plugin/views/exposed_form/Os2webBasic.php @@ -0,0 +1,31 @@ +request->all(), \Drupal::request()->query->all()); + $view->setExposedInput($exposed_input); + } + +} From 77a0cb1047fef950b2b5e4b03d5127e00b567152 Mon Sep 17 00:00:00 2001 From: andriyun Date: Thu, 10 Mar 2022 16:23:46 +0100 Subject: [PATCH 2/2] Adjuted comments --- src/Plugin/views/display/Os2webRestExport.php | 4 ++-- src/Plugin/views/exposed_form/Os2webBasic.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Plugin/views/display/Os2webRestExport.php b/src/Plugin/views/display/Os2webRestExport.php index 4327df5..9fd7979 100644 --- a/src/Plugin/views/display/Os2webRestExport.php +++ b/src/Plugin/views/display/Os2webRestExport.php @@ -13,8 +13,8 @@ * * @ViewsDisplay( * id = "os2web_rest_export", - * title = @Translation("OS2Web REST export"), - * help = @Translation("Create a OS2Web REST export resource."), + * title = @Translation("OS2Web REST export, GET, POST"), + * help = @Translation("Create a OS2Web REST export resource with ability GET, POST requests."), * uses_route = TRUE, * admin = @Translation("OS2Web REST export"), * returns_response = TRUE diff --git a/src/Plugin/views/exposed_form/Os2webBasic.php b/src/Plugin/views/exposed_form/Os2webBasic.php index e16b98a..ee45c3b 100644 --- a/src/Plugin/views/exposed_form/Os2webBasic.php +++ b/src/Plugin/views/exposed_form/Os2webBasic.php @@ -13,8 +13,8 @@ * * @ViewsExposedForm( * id = "os2web_basic", - * title = @Translation("OS2Web Basic"), - * help = @Translation("OS2Web Basic exposed form") + * title = @Translation("OS2Web Basic. GET, POST"), + * help = @Translation("OS2Web Basic exposed form. GET, POST") * ) */ class Os2webBasic extends Basic {