diff --git a/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block3.yml b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block3.yml new file mode 100644 index 0000000..f10d388 --- /dev/null +++ b/core/modules/block/tests/modules/block_test_views/test_views/views.view.test_view_block3.yml @@ -0,0 +1,58 @@ +langcode: en +status: true +dependencies: { } +id: test_view_block3 +label: test_view_block3 +module: views +description: '' +tag: '' +base_table: views_test_data +base_field: id +core: 8.x +display: + default: + display_plugin: default + id: default + display_title: Master + position: null + display_options: + access: + type: none + cache: + type: tag + query: + type: views_query + exposed_form: + type: basic + pager: + type: some + options: + items_per_page: 5 + style: + type: default + row: + type: fields + fields: + name: + id: name + table: views_test_data + field: name + filters: + name: + id: string + table: views_test_data + plugin_id: string + field: name + operator: contains + value: '' + exposed: true + expose: + operator_id: name_op + label: 'Name' + title: test_view_block + use_ajax: true + block_1: + display_plugin: block + id: block_1 + display_title: Block + position: null diff --git a/core/modules/views/src/Form/ViewsExposedForm.php b/core/modules/views/src/Form/ViewsExposedForm.php index 372d963..d4d78be 100644 --- a/core/modules/views/src/Form/ViewsExposedForm.php +++ b/core/modules/views/src/Form/ViewsExposedForm.php @@ -111,7 +111,12 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#id' => Html::getUniqueId('edit-submit-' . $view->storage->id()), ); - $form['#action'] = $view->hasUrl() ? $view->getUrl()->toString() : Url::fromRoute('')->toString(); + if (isset($view->override_path)) { + $form['#action'] = $view->override_path; + } + else { + $form['#action'] = $view->hasUrl() ? $view->getUrl()->toString() : Url::fromRoute('')->toString(); + } $form['#theme'] = $view->buildThemeFunctions('views_exposed_form'); $form['#id'] = Html::cleanCssIdentifier('views_exposed_form-' . $view->storage->id() . '-' . $display['id']); diff --git a/core/modules/views/src/Form/ViewsForm.php b/core/modules/views/src/Form/ViewsForm.php index b124d65..c2bff96 100644 --- a/core/modules/views/src/Form/ViewsForm.php +++ b/core/modules/views/src/Form/ViewsForm.php @@ -157,7 +157,12 @@ public function buildForm(array $form, FormStateInterface $form_state, ViewExecu $query = UrlHelper::filterQueryParameters($query, array(), ''); $options = array('query' => $query); - $form['#action'] = $view->hasUrl() ? $view->getUrl()->setOptions($options)->toString() : Url::fromRoute('')->setOptions($options)->toString(); + if (isset($view->override_path)) { + $form['#action'] = $view->override_path; + } + else { + $form['#action'] = $view->hasUrl() ? $view->getUrl()->setOptions($options)->toString() : Url::fromRoute('')->setOptions($options)->toString(); + } // Tell the preprocessor whether it should hide the header, footer, pager, // etc. $form['show_view_elements'] = array( diff --git a/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php index d06ae66..887650e 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/ViewsBlockTest.php @@ -26,7 +26,7 @@ class ViewsBlockTest extends ViewsKernelTestBase { * * @var array */ - public static $testViews = array('test_view_block'); + public static $testViews = array('test_view_block', 'test_view_block3'); /** * {@inheritdoc} @@ -127,4 +127,20 @@ public function testBuildWithTitleOverride() { $this->assertEquals('Overridden title', $build['#title']['#markup']); } + /** + * Tests ViewsBlock::build() with a path override. + * + * @see \Drupal\views\Plugin\Block::build() + */ + public function testBuildWithPathOverride() { + $path = '/viewstestpath'; + + $view = Views::getView('test_view_block3'); + $view->setDisplay(); + $view->override_path = $path; + + $build = $view->render('block_1'); + $this->assertEquals($path, $build['#view']->exposed_widgets['#action']); + } + }