diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 9889c93e32..c4afbd7843 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -942,6 +942,50 @@ function hook_views_ui_display_top_links_alter(array &$links, ViewExecutable $vi } } +/** + * Alter the top of the display for the Views UI. + * + * This hook can be implemented by themes. + * + * @param array $build + * The edit page. + * @param \Drupal\views_ui\ViewUI $view + * The view being edited. + * @param string $display_id + * The display ID. + * + * @todo Until https://www.drupal.org/project/drupal/issues/3087455 is resolved, + * use this hook or hook_views_ui_display_tab_alter() instead of + * hook_form_view_edit_form_alter(). + * + * @see \Drupal\views_ui\ViewUI::renderDisplayTop() + */ +function hook_views_ui_display_top_alter(&$build, \Drupal\views_ui\ViewUI $view, $display_id) { + $build['custom']['#markup'] = 'This text should always appear'; +} + +/** + * Alter the renderable array representing the edit page for one display. + * + * This hook can be implemented by themes. + * + * @param array $build + * The edit page. + * @param \Drupal\views_ui\ViewUI $view + * The view being edited. + * @param string $display_id + * The display ID. + * + * @todo Until https://www.drupal.org/project/drupal/issues/3087455 is resolved, + * use this hook or hook_views_ui_display_tab_alter() instead of + * hook_form_view_edit_form_alter(). + * + * @see \Drupal\views_ui\ViewEditForm::getDisplayTab() + */ +function hook_views_ui_display_tab_alter(&$build, \Drupal\views_ui\ViewUI $view, $display_id) { + $build['custom']['#markup'] = 'This text should always appear'; +} + // @todo Describe how to alter a view ajax response with event listeners. /** diff --git a/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php b/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php index 5444eb93bc..6b7cd1226f 100644 --- a/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php +++ b/core/modules/views_ui/tests/src/FunctionalJavascript/DisplayTest.php @@ -122,4 +122,29 @@ protected function toggleContextualTriggerVisibility($selector) { $this->getSession()->executeScript("jQuery('{$selector} .contextual .trigger').toggleClass('visually-hidden');"); } + /** + * Confirms that form_alter is triggered after ajax rebuilds. + */ + public function testAjaxRebuild() { + \Drupal::service('theme_installer')->install(['views_test_classy_subtheme']); + + $this->config('system.theme') + ->set('default', 'views_test_classy_subtheme') + ->save(); + + $page = $this->getSession()->getPage(); + $assert_session = $this->assertSession(); + + $this->drupalGet('admin/structure/views/view/content'); + $assert_session->pageTextContains('This is text added to the display tabs at the top'); + $assert_session->pageTextContains('This is text added to the display edit form'); + $page->clickLink('Content: Title (Title)'); + $assert_session->waitForElementVisible('css', '.views-ui-dialog'); + $page->fillField('Label', 'New Title'); + $page->find('css', '.ui-dialog-buttonset button:contains("Apply")')->press(); + $assert_session->waitForElementRemoved('css', '.views-ui-dialog'); + $assert_session->pageTextContains('This is text added to the display tabs at the top'); + $assert_session->pageTextContains('This is text added to the display edit form'); + } + } diff --git a/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml new file mode 100644 index 0000000000..fbac46814d --- /dev/null +++ b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.info.yml @@ -0,0 +1,6 @@ +name: 'Theme test subtheme' +type: theme +description: 'Test theme which uses test_basetheme as the base theme.' +version: VERSION +core: 8.x +base theme: classy diff --git a/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.theme b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.theme new file mode 100644 index 0000000000..cb643bc4bd --- /dev/null +++ b/core/modules/views_ui/tests/themes/views_test_classy_subtheme/views_test_classy_subtheme.theme @@ -0,0 +1,22 @@ +