diff --git a/core/modules/system/src/Tests/Common/PageRenderTest.php b/core/modules/system/src/Tests/Common/PageRenderTest.php index e660448f42dbb65770e9f59656c59427eda91224..e9eb691b536c6b8d1d7943a60f6b98516e27455b 100644 --- a/core/modules/system/src/Tests/Common/PageRenderTest.php +++ b/core/modules/system/src/Tests/Common/PageRenderTest.php @@ -33,24 +33,6 @@ function testHookPageAlter() { $this->assertPageRenderHookExceptions('common_test', 'hook_page_attachments_alter'); } - /** - * Tests hook_page_build() exceptions, a deprecated hook kept around for BC. - */ - function testHookPageBuildExceptions() { - // Also enable the system module, because that module invokes the BC hooks. - $this->enableModules(['bc_test', 'system']); - $this->assertPageRenderHookExceptions('bc_test', 'hook_page_build'); - } - - /** - * Tests hook_page_alter(), a deprecated hook kept around for BC. - */ - function testHookPageAttachmentsAlter() { - // Also enable the system module, because that module invokes the BC hooks. - $this->enableModules(['bc_test', 'system']); - $this->assertPageRenderHookExceptions('bc_test', 'hook_page_alter'); - } - /** * Asserts whether expected exceptions are thrown for invalid hook implementations. * diff --git a/core/modules/system/system.module b/core/modules/system/system.module index ba268445def101856c5e62c0a703864710813dd3..9334a8881e339390807868fe1bea1629fffc9501 100644 --- a/core/modules/system/system.module +++ b/core/modules/system/system.module @@ -632,28 +632,6 @@ function system_page_attachments(array &$page) { ) ); } - - // Invoke hook_page_build() for modules and hook_page_alter() for both modules - // and themes, for backwards compatibility. - $attachments = []; - foreach (\Drupal::moduleHandler()->getImplementations('page_build') as $module) { - $function = $module . '_page_build'; - $function($attachments); - } - if (array_diff(array_keys($attachments), ['#attached', '#post_render_cache']) !== []) { - throw new \LogicException('Only #attached and #post_render_cache may be set in hook_page_build().'); - } - \Drupal::moduleHandler()->alter('page', $attachments); - \Drupal::theme()->alter('page', $attachments); - if (array_diff(array_keys($attachments), ['#attached', '#post_render_cache']) !== []) { - throw new \LogicException('Only #attached and #post_render_cache may be set in hook_page_alter().'); - } - if (isset($attachments['#attached'])) { - $page['#attached'] = $attachments['#attached']; - } - if (isset($attachments['#post_render_cache'])) { - $page['#post_render_cache'] = $attachments['#post_render_cache']; - } } /** diff --git a/core/modules/system/tests/modules/bc_test/bc_test.info.yml b/core/modules/system/tests/modules/bc_test/bc_test.info.yml deleted file mode 100644 index 20dbd821dbacc4eca9a58b48042060c20076639d..0000000000000000000000000000000000000000 --- a/core/modules/system/tests/modules/bc_test/bc_test.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'Backwards Compatibility Test' -type: module -description: 'Support module for backwards compatibility tests.' -package: Testing -version: VERSION -core: 8.x diff --git a/core/modules/system/tests/modules/bc_test/bc_test.module b/core/modules/system/tests/modules/bc_test/bc_test.module deleted file mode 100644 index 537acb83797b3319c32448df0397ed58cd64e8f8..0000000000000000000000000000000000000000 --- a/core/modules/system/tests/modules/bc_test/bc_test.module +++ /dev/null @@ -1,44 +0,0 @@ -get('bc_test.hook_page_build.descendant_attached', FALSE)) { - $page['content']['#attached']['library'][] = 'core/jquery'; - } - - if (\Drupal::state()->get('bc_test.hook_page_build.render_array', FALSE)) { - $page['something'] = [ - '#markup' => 'test', - ]; - } -} - -/** - * Implements hook_page_alter(). - * - * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions() - */ -function bc_test_page_alter(&$page) { - $page['#attached']['library'][] = 'core/jquery'; - - if (\Drupal::state()->get('bc_test.hook_page_alter.descendant_attached', FALSE)) { - $page['content']['#attached']['library'][] = 'core/jquery'; - } - - if (\Drupal::state()->get('bc_test.hook_page_alter.render_array', FALSE)) { - $page['something'] = [ - '#markup' => 'test', - ]; - } -} diff --git a/core/modules/system/tests/modules/common_test/common_test.module b/core/modules/system/tests/modules/common_test/common_test.module index 97ff0bf22b7baf231bf1503bf992723373e5c51f..a1100b43c0eb3cf098a5459735d89265245bcc10 100644 --- a/core/modules/system/tests/modules/common_test/common_test.module +++ b/core/modules/system/tests/modules/common_test/common_test.module @@ -260,7 +260,8 @@ function common_test_post_render_cache_placeholder(array $element, array $contex * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions() */ function common_test_page_attachments(array &$page) { - $page['#attached']['library'][] = 'core/jquery'; + $page['#attached']['library'][] = 'core/foo'; + $page['#attached']['library'][] = 'core/bar'; if (\Drupal::state()->get('common_test.hook_page_attachments.descendant_attached', FALSE)) { $page['content']['#attached']['library'][] = 'core/jquery'; @@ -279,7 +280,12 @@ function common_test_page_attachments(array &$page) { * @see \Drupal\system\Tests\Common\PageRenderTest::assertPageRenderHookExceptions() */ function common_test_page_attachments_alter(array &$page) { - $page['#attached']['library'][] = 'core/jquery'; + // Remove a library that was added in common_test_page_attachments(), to test + // that this hook can do what it claims to do. + if (isset($page['#attached']['library']) && ($index = array_search('core/bar', $page['#attached']['library'])) && $index !== FALSE) { + unset($page['#attached']['library'][$index]); + } + $page['#attached']['library'][] = 'core/baz'; if (\Drupal::state()->get('common_test.hook_page_attachments_alter.descendant_attached', FALSE)) { $page['content']['#attached']['library'][] = 'core/jquery'; diff --git a/core/modules/system/theme.api.php b/core/modules/system/theme.api.php index 1ba2efca421b82fca415f3e4c788a5d5321f4c70..f13210da094031c294d752b19bb30df0283dac97 100644 --- a/core/modules/system/theme.api.php +++ b/core/modules/system/theme.api.php @@ -810,60 +810,6 @@ function hook_css_alter(&$css) { unset($css[drupal_get_path('module', 'system') . '/defaults.css']); } -/** - * Add attachments (typically assets) to a page before it is rendered. - * - * Kept around for backwards compatibility, but now allows only attachments to - * be added, adding renderable arrays is no longer allowed. - * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. Successor: - * hook_page_attachments(). Is now effectively an alias of that hook. - * - * @param $page - * The page to which to add attachments. - * - * @see hook_page_attachments() - */ -function hook_page_build(&$page) { - $path = drupal_get_path('module', 'foo'); - // Add JavaScript/CSS assets to all pages. - // @see drupal_process_attached() - $page['#attached']['js'][$path . '/foo.js'] = array('every_page' => TRUE); - $page['#attached']['css'][$path . '/foo.base.css'] = array('every_page' => TRUE); - $page['#attached']['css'][$path . '/foo.theme.css'] = array('every_page' => TRUE); - - // Add a special CSS file to a certain page only. - if (drupal_is_front_page()) { - $page['#attached']['css'][] = $path . '/foo.front.css'; - } -} - -/** - * Perform alterations before a page is rendered. - * - * Kept around for backwards compatibility, but now allows only attachments to - * be added, altering the renderable array for the page is no longer allowed. - * - * @deprecated in Drupal 8.x, will be removed before Drupal 9.0. Successor: - * hook_page_attachments_alter(). Is now effectively an alias of that hook. - * - * Use this hook when you want to remove or alter attachments at the page - * level, or add attachments at the page level that depend on an other module's - * attachments (this hook runs after hook_page_build(). - * - * @param $page - * An empty renderable array representing the page. - * - * @see hook_page_build() - */ -function hook_page_alter(&$page) { - // Conditionally remove an asset. - if (in_array('core/jquery', $page['#attached']['library'])) { - $index = array_search('core/jquery', $page['#attached']['library']); - unset($page['#attached']['library'][$index]); - } -} - /** * Add attachments (typically assets) to a page before it is rendered. * diff --git a/core/modules/views/views.module b/core/modules/views/views.module index f2a0b376844e8ce7a7d1d395f0b1515a7fca4b91..507758c05c41d627fa7bf394ab5839472edb9dca 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -388,7 +388,7 @@ function views_preprocess_html(&$variables) { * The ID of the display within $view whose contextual links will be added. * * @see \Drupal\views\Plugin\block\block\ViewsBlock::addContextualLinks() - * @see views_page_alter() + * @see views_preprocess_page() * @see template_preprocess_views_view() */ function views_add_contextual_links(&$render_element, $location, ViewExecutable $view, $display_id) {